Does that remove the Dictionary from the Dictionary list?
Yes. A Dictionary only exists if it has keys, and a key only exists if it has a value.
OK, that’s good. Some could argue that ""
is a value, a empty string. Different from null or missing value.
This makes KM Dictionaries different from KM Variables. A KM Variable continues to exist, even if it’s value is ""
, unless you set it to “%Delete%”.
To be honest, I’d prefer the same approach with Dictionaries.
A Dictionary should exist until I set it to “%Delete%”, but since we can only set Dictionary keys, I guess we’d need a KM Action to “Delete Dictionary”.
No, it doesn't actually.
A variable stops existing if it has an empty value.
Keyboard Maestro typically lists both variables that exist and variables that are used in any action.
A variable actually still exists if it is set to %Delete%, but then it is explicitly excluded from being listed in most places.
If you create an action, set a variable to a value, then set it to the empty string, then delete the action, the variable will not be listed in the Variables pane.
Thanks for clarifying. That is not intuitive to me. I've never seen variables behave like that in any other language.
It adds to my confusion that a variable with an empty value does NOT exist, yet it shows up in the Variables Pane, and in the Variable list. If it doesn't exist, how can it show?
I guess it depends on the definition of "is", er a "exists".
It also seems like deleting a variable would cause it to cease to exist.
If I use a variable just deleted in a Macro with an If/Then, the If/Then treats it as if it does NOT exist:
It depends on your idea of existence, of what the variable really means, and what it means to delete it.
It’s considered to not exist if it is set to %Delete%, but if it has a value of %Delete%, then by definition it must exist to some degree.
The Preferences window and the popups in the editor show variables for your use, so they include variables that are used, whether they exist or not.
The %Delete% thing is really just for people who don’t want every variable showing up in popup menus - personally I never use it. Hence, don’t expect it to fit with my idea of consistency - it was added for people who explicitly wanted the facility, sometimes I allow my natural consistency to be swayed away by other people’s desire for specific features. Usually this results in different kinds of pain going forward, such as a lack of clarity in what a variable’s existence means, or a lack of clarity in whether a macro group is active. Hopefully the benefits in these cases outweigh the negatives.
But the “natural” concept in Keyboard Maestro is:
- If you set a variable (or dictionary entry) to “”, then it no longer exists
- The popup menus will show you variables that don’t exist if they are used somewhere in a macro.
- The %Delete% is a hack to hide variables, but otherwise is the same as not existing, more or less, sort of.
Ah ha. I would see that at the end of various macros here and wonder if it was good housekeeping or not. But preferred to skip it (although I keep house well enough) to keep my macro lean.
Thanks for the clarification.
Thanks for the clarification, Peter.
I will try to update the KM Wiki to reflect your post, so that it will be clear to everyone.
Yes, as a general rule, the only variables I clear are either ones that might contain sensitive information, or ones that might be very large.
To each his own.
I don't like a lot of garbage hanging around in my variable list that is ONLY needed within one Macro. That's why I like the new Local/Instance variable so much.