The Keyboard Maestro solution provider (@gglick) gave me this gem/gift about two years ago:
I'm sure you will find your solution. As far as time savings and efficiency, this creation gets the most usage and has made my job so much easier. Gabe is so humble but his contributions, on this forum, are magnificent.
Dan,
thank for the macro which is using the method from Keyboard Maestro 4 Documentation: Scripting eg example
tell application "Keyboard Maestro Engine"
do script "MacroActionTypeSwitchToLastApplication"
end tell
You could actually remove the ActionUID - I think it will work fine without it. But no, KM automatically changes it to a new value when you import it, or you run it.
Dan,
"You could actually remove the ActionUID - I think it will work fine without it. But no, KM automatically changes it to a new value when you import it, or you run it."
come to think of it . You are correct that it can be ignored since it does not belong to any macro. It is actually a anonymous action .The actionUID is there because we use "Copy as XML" on selected action of existing macro.
Now I understand why Peter's example in the wiki show without ActionUID
tell application "Keyboard Maestro Engine"
do script "<dict><key>MacroActionType</key><string>SwitchToLastApplication</string></dict>"
end tell
do script found no macros with a matching name (macros must be enabled, and in macro groups that are enabled and currently active).
Such an odd error. The error message suggests it knew what I wanted to do, but somehow the blank line at the start confused it. As soon as I removed the blank line, it worked.
I guess the blank line at the end doesn't matter. Anyway, the issue with a blank line at the start has existed for as long as I've done these types of scripts.