What you want involves decision making, and that is the difference between a macro facility as we have in Cubase, and a scripting facility. Some macro commands are specifically pre-programmed to toggle e.g. Loop on/off, Cursor scroll on/off, etc. but unless the macro command has already been specifically programmed as a toggle, you can’t do it yourself.