To expound on the good advice @noisneil and @tiffle have shared, I use global variables extensively while creating, modifying or debugging a macro.
For instance, when creating a new macro, I use global variables and prepend them with debug__
, that way if I see them in the variable pane in the KM preferences window, I know they are for a macro I am currently working on. But, since they are global (I.e. persistent in that they don’t go away and their content does not change unless one of my actions changes it), I may need them to be “reset” at the beginning of each macro execution. For example, if the macro I am building appends text to a variable, then I likely need that variable reset before each execution that way it doesn’t get superfluous text in it. For this case, I use the following AppleScript at the beginning of the macro to first set the content of all variables that begin with debug__
to “BLANK”, and then I delete them.
AppleScript to empty and delete all debug__ variables (click to expand/collapse)
set varName1 to "debug__"
set varAction1 to "BLANK"
set varAction2 to "%Delete%"
tell application "Keyboard Maestro Engine"
set value of variables whose name starts with varName1 to varAction1
set value of variables whose name starts with varName1 to varAction2
end tell
AppleScript explanation:
I use variables (such as varName1 and varAction1) to simplify certain things.
varName1 is how the variable is prepended.
varAction1 is to set those variable to “BLANK” first.
varAction2 is to then delete those variables.so the line:
set value of variables whose name starts with varName1 to varAction1
is basically telling Keyboard Maestro Engine to set all variables that start withdebug__
to “BLANK”, and the next line is telling it to delete them.
Why set them to “BLANK” first? Because I have found that if a global variable does not contain any text, then AppleScript does not actually delete it. The why of this is beyond both my comprehension and my desire to understand it. Suffice it to say, I just don’t care, as long as it goes away and no longer clutters up my variables list.
To wrap this up, once I have finished building, modifying or debugging the macro in question, I have a macro that automatically converts all debug__
variables into local__
variables that way I don’t have to worry about it anymore.
If this doesn’t make sense, or you want to see some examples, feel free to reach out and I’d be happy to explain further.
-Chris