I am looking for a way to deactivate a list of macro groups in one go.
Because the list is not fixed, l would like to do this programmatically, with some help from Applescript (think: deactivate every macro group whose name begins with "•".)
However, as far as I can see, I can set the "enabled" property of a macro group to false in Applescript, but there is no similar "activated" property, or "activate" command.
And the disactivating macro that is available in KM itself does not take variables.
It sounds like you want it to be dynamic rather than just add in the macro groups that you want to deactivate. Also to be sure you want to deactivate which only deactivates on the computer you (not any synced computers) are on and not disable. I disable and enable groups frequently based on different paramaters and do like that in the Keyboard Maestro you also see that they are disabled, with a hot key but haven't tried to do that by name which seems doable.
Do note that with diabled you can't call on them via AppleScript to run currently but you can call on them to run even when disabled to still run so really it is only disabling the trigger and Keyboard Maestro considers AppleScript calling them to be a trigger.
tell application "Keyboard Maestro"
tell (macro groups whose name begins with "A")
set enabled to false
end tell
end tell
tell application "Keyboard Maestro"
tell (macro groups whose name begins with "A")
set enabled to true
end tell
end tell
First -- have a read of this thread, paying particular attention to @peternlewis's posts, and decide whether you want to "deactivate" or "disable" the Groups.
Then decide whether you are happy to have the KM Editor open to do this (I have it running all the time so it wouldn't matter to me, other people quit the Editor when not editing macros) -- how you get the Group names will depend on this.
Or are you happy to maintain a hard-coded list of Groups to change, rather than programmatically getting "every Group whose name starts with •"?
Thanks for thinking along with me about this.
But I'm not looking to disable groups. If I do that, any key shortcut that activates them won't work any more, as "skillet mentions in his reply to this.
I want their key shortcuts to be available to activate these groups, but be able to disactivate them all in one go. And I don't see yet how to do that.
Thanks for the advice!
Applescript has no problem giving me a list that corresponds to my filter.
It's the next step I'm stuck with: deactivating (not disabling) all the groups in that list.
I don't see a link to the thread?
tell application "Keyboard Maestro"
set groupList to (get id of every macro group whose name starts with "•")
end tell
tell application "Keyboard Maestro Engine"
repeat with UUID in groupList
do script "<dict>
<key>DisplayToggle</key>
<true/>
<key>MacroActionType</key>
<string>MacroGroupToggle</string>
<key>MacroGroupUID</key>
<string>" & UUID & "</string>
<key>ToggleMode</key>
<string>Deactivate</string>
</dict>"
end repeat
end tell
I've left DisplayToggle on <true/> so you get an indicator -- change to <false/> if that annoys. If you want to use the same macro to toggle the Groups between "activated" and "deactivated", change ToggleMode to Toggle.
(I use KM a lot, but somehow I never got around to, or to be honest even encountered, the ... way of automating the engine.)
However, on running it (as is in the AppleScript editor) it gets the UUID list just fine, but after every run of the do script for a UUID block the editor reports a "missing value" and the groups do not get deactivated. Any idea what could be the problem?
You'll get "missing value" if you set the action to "Display results in a window" -- do script (the last evaluation) returns nothing if the script doesn't include a "Return" action.
If you've read the thread I linked you'll know that there is no UI indicator in the Editor that a Group is inactive and that you can't deactivate an already deactivated Group. What you'll need to do to test this macro is to first make the Groups active -- eg by making sure they are set to "Always activated" in the Editor, then quitting and relaunching the KM Engine -- before running the macro, or leave DisplayToggle set to <true/> and change the ToggleMode to Toggle so you can see them switch modes.
This now works great, thanks so much!
It does not work when run from the Applescript editor, for some reason. Normally I test stuff there before I paste it into a macro. This one only works in the latter case. I am curious as to why.