I have a macro that increments-number-by-step. Currently when I run the macro, I have to set the counter and the counterIncrement using another macro that prompts the user to enter the variables for counter and counterIncrement.
What I would like to do is the increment-a-number script to check if the variables are defined, if not ask the user to set them
Here is the pseudocode
GIVEN there are 2 variables counter & counterIncrement
* WHEN the script starts
* IF they are not-defined
* THEN a prompt is shown to set the variables
* WHEN Keyboard Maestro Quits
* IF they are defined
* THEN the 2 variables are un-set
How can I check if a variable has a value or is un-defined or NULL when a script starts ?
Keyboard Maestro variables are names bound to String values. The special (in some circles notorious) JavaScript values of undefined and null are not part of the picture, but:
A KM variable name may be bound to an empty string, or
it may not exist at all (i.e. its name may not be found in the name-space of defined KM variables)
Keyboard Maestro IF THEN ELSE blocks offer Variable conditions
allowing you to test for existence and/or empty strings.
You can also remove a variable name from the name-space by assigning it to the value of the special token %Delete%, after which the does not exist test will return a true value for that variable name.