I'm starting to use AppleScript to control KM itself—very powerful!
I've run into a complication when I try to add a case entry. I have a Switch/Case action with a lot of cases, and then a final "otherwise" case. I'm adding new case entries with AppleScript like this:
tell myAction
make new case entry with properties {xml:"<dict><key>Actions</key><array/> ... </dict>"}
end tell
This creates the case entry I've defined, but it adds it to the end of the Switch/Case action—after the "otherwise" case entry. As a result the new case entry is never triggered, because the "otherwise" condition always gets triggered first.
Is there a way to insert the new case entry in the penultimate position, or the top position, rather than at the end?
tell application id "com.stairways.keyboardmaestro.editor"
set m to macro "AppleScript Case Entry Tester"
tell m
tell action "AppleScript Case Entry Tester Switch/Case Action"
make new case entry with properties {xml:"
<dict>
<key>Actions</key>
<array>
<dict>
<key>IsDisclosed</key>
<false/>
<key>MacroActionType</key>
<string>Notification</string>
<key>Title</key>
<string>contains h</string>
</dict>
</array>
<key>ConditionType</key>
<string>Contains</string>
<key>TestValue</key>
<string>h</string>
</dict>
"}
end tell
end tell
end tell
When I do this, it adds a case entry at the end of the switch/case action, after the "otherwise" case entry.
tell application id "com.stairways.keyboardmaestro.editor"
set m to macro "AppleScript Case Entry Tester"
tell m
tell action "AppleScript Case Entry Tester Switch/Case Action"
make new case entry with properties {xml:"
<dict>
<key>Actions</key>
<array>
<dict>
<key>IsDisclosed</key>
<false/>
<key>MacroActionType</key>
<string>Notification</string>
<key>Title</key>
<string>contains h</string>
</dict>
</array>
<key>ConditionType</key>
<string>Contains</string>
<key>TestValue</key>
<string>h</string>
</dict>
"} at beginning of every case entry of it
end tell
end tell
end tell
And you can use at beginning or at end of case entries.
-Chris
tell application id "com.stairways.keyboardmaestro.editor"
set m to macro "AppleScript Case Entry Tester"
tell m
tell action "AppleScript Case Entry Tester Switch/Case Action"
make new case entry at before last case entry with properties {xml:"
<dict>
<key>Actions</key>
<array>
<dict>
<key>IsDisclosed</key>
<false/>
<key>MacroActionType</key>
<string>Notification</string>
<key>Title</key>
<string>contains h</string>
</dict>
</array>
<key>ConditionType</key>
<string>Contains</string>
<key>TestValue</key>
<string>h</string>
</dict>
"}
end tell
end tell
end tell
Experimentation is the name of the game. Try it and see...
But – these all work:
make new case entry at before first case entry with properties {xml: …
make new case entry at after first case entry with properties {xml: …
make new case entry at before last case entry with properties {xml: …
make new case entry at after last case entry with properties {xml: …
make new case entry at before case entry 2 with properties {xml: …
make new case entry at after case entry 2 with properties {xml: …