I've just re-installed Dan's [KMFAM] Favorite Actions and Macros with plans to use it again going forward and notice quite a few variables with a kmfam prefix. I also continue to use JMichaelTX's [KM] [DELETE All Variables Except Those on Keep List] and wonder if all the other kmfam variables not prefixed with DND__ are safe to delete and exclude from the DND__KM_Vars_To_Keep list?
tell application "Keyboard Maestro Engine"
set value of variables whose name starts with "kmfam" to "%Delete%"
end tell
It doesn't appear to work. For some reason, the KM Engine isn't able to find variables that start with "kmfam", or at least not all of them. I've verified this in Script Debugger also.
I'm hoping you use KMFAM and can figure out if I've done something wrong somehow, or if this is a bug in the engine. If not, do you have any other ideas?
I pasted the delete actions from "[KMFAM] Select" into a macro for use after invoking [KMFAM]. The first screenshot shows the variables created from the use of the [KMFAM] utility.
Additionally, its still not clear what variable names to list in JMichaelTX's macro "Keyboard Maestro Delete Variables Except Those On Keep List". I've listed the two below with and without the DND__ prefix, but his macro deletes them. So, on the next run of your utility, I have to again report/declare the KMFAM Resources folder path.
I just ran a test using SD7, and it appears that AppleScript can NOT see (have access to) KM variables that are empty (no value shows in KM Prefs).
tell application "Keyboard Maestro Engine"
set value of variables whose name starts with "kmfam" to "%Delete%"
set kmVarList to name of variables whose name starts with "kmfam"
end tell
AppleScript found and deleted these variables which also showed in the KM Prefs:
However variables that are used in any macro in Keyboard Maestro will still be displayed in the Preferences or in the popup menus for selecting variables or the like.
But they don't exist as far as AppleScript is concerned.
Just to add clarity to how Variables work with Keyboard Maestro:
You delete a variable by setting it to the empty string. At that point it is removed from the variables database.
Keyboard Maestro will show you variables that have values as well as variables you use in any macro in the Variables preference pane, and in Variables popup menus and Insert Variable by Name or Insert Variables menu.
You can actively hide a variable from those displayed locations by setting its value to the special token %Delete%. However this does not delete the variable from the database, in fact the opposite, it ensures it is in the database with this special value.
For variables you want to delete at the end of the macro, perhaps you should move to using Local or Instance variables?
Peter, I hope you can appreciate contradiction in terms that this presents.
At this point, I see no value in the %Delete% token.
Yep, this is what I now do. For all new Macros I've written since KM 8.0.2, I've used Local/Instance variables, unless I want the variable to persist across executions and macros. Then, I prefix these with "DND_".
The major downside of this is that there is no easy way to inspect Local/Instance variables while debugging a macro. It would sure be nice if the KM Debugger would show Loca/Instance variables, like most debuggers I have ever used.
Yes, and no. It does not delete the variable, it deletes the variable from the Popup menus and Preferences and such.
The purpose of the token is to hide variables from the Popup menu that selects Variables.
Yes, it would, and yes it is a pain, but currently that is unlikely any time soon I'm afraid.
The solutions are to use tools like Log and Display Text and such to display the variables as necessary. It is not ideal, but it is what it is. If it is any consultation (probably not) it is how I generally debug Keyboard Maestro since the debugger generally does not show me variables there either.