I thought it would be a very useful script that will find, select and remove every disabled action in the current macro. Can anyone help me write this using AppleScript? I tried, but I don't know AS very well yet.. Thanks in advance!
hey @magikCT did you find a way to do this?
Tried searching the Wiki, but didn't find any Search Qualifiers for actions.
How about this:
(* AppleScript used in the KM macro Remove All Disabled Actions to loop through all the actions in the currently-selected macro in the KM Editor and delete the disabled actions. *) --use AppleScript version "2.4" -- Yosemite (10.10) or later --use scripting additions tell application "Keyboard Maestro" try --ensure we have only 1 selected macro if ((count of selected macros) = 1) then --get the current macro, if any set selMacros to selected macros --get every action of item 1 of selMacros ----and put them in a list set selActionList to every action in item 1 of selMacros --loop through the list of actions repeat with selAction in selActionList if get enabled of selAction is false then delete selAction end repeat end if end try end tell
Embed the code in an Execute AppleScript action in a macro.
Remove All Disabled Actions.kmmacros (3.4 KB)
Works for me but use carefully as it is destructive.
Given my inexperience with AppleScript there may be more efficient ways to do this...
BTW - you need to to trigger this macro while the one you want to change is open in the KM editor.
Thanks a lot, very useful @tiffle!
AWESOME! Thanks a lot!
I've found a problem with this "solution" of mine.
If you have something like this in your macro:
my AppleScript will not delete the disabled Play Sound action.
In fact, the contents of any action like If..Then...Else, Switch, Group, For Each etc that lets you nest other actions inside it will be completely ignored by my AppleScript.
The reason is simple:
picks out only the top level actions, not any other actions nested within.
I don't have a solution to this and I'm afraid I won't be providing one as it requires a greater degree of AppleScript expertise than I currently possess.
Maybe some kind soul (=expert) will fill in the gaps...
Yep, and there is no easy way to select all Actions at all levels in a Macro.
It would be very, very useful if the KM Editor would support a statement like this:
set actionList to every action in macro MacroNameOrUUIDorObject
This would require a change by @peternlewis to the KM Editor scripting model.
Peter, please consider this an enhancement request.
I have a solution to the problem. It was staring me in the face. As part of another project I had some AppleScript that was really easy to modify so it performs the task of deleting disabled actions in a macros, regardless of how "nested" they are.
This is the AppleScript file:
Delete all Disabled Actions.scpt.zip (2.9 KB)
Download it and unzip to somewhere on your Mac.
Then create your "Delete all disabled actions" macro in KM with just a single action to run this AppleScript file, like this:
(Point the action to wherever you saved the AppleScript file - I put the file on my Desktop just for simplicity when testing.)
Here's the macro I used:
Delete All Disabled Actions.kmmacros (2.4 KB)
Please note: because the AppleScript code is part of a larger system I am developing I can only provide the runtime (i.e. non-editable) version.
The code itself is quite complicated and so may take a few seconds to complete the task you set it. You could add a Play Sound action at the end of the macro to tell you when it has finished!
The usual caveats apply: this code is destructive and while I have tested it without any problems you should use it with care and make a copy of any macro you use it on first!
If you try this out let me know how you get on.