How do enable/disable macro group with Applescript using Keyboard Maestro Engine (not Editor)?

I check that enable/disable macro group can be done in KM Editor using Applescript manual:Scripting [Keyboard Maestro Wiki]

Is it possible to do it in engine instead ?
The following didn't work

tell application "Keyboard Maestro Engine"
set enabled of macro group "My Macro Group" to false
end tell

Unable to locate the past answer in forum, so wonder if it is possible to do it in the engine without opening the KM editor.

@macdevign_mac ,

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.

I hope this helps you macdevign.

KC

1 Like

Try this and let me know if it works for you. Requires KM 10:

Usage

image

Macro

image

Activate:Deactivate Group.kmmacros (7.3 KB)

1 Like

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

the xml section reference

`<dict>
	<key>ActionUID</key>
	<integer>492039</integer>
	<key>DisplayToggle</key>
	<false/>
	<key>MacroActionType</key>
	<string>MacroGroupToggle</string>
	<key>MacroGroupUID</key>
	<string>${groupUUID}</string>
	<key>ToggleMode</key>
	<string>${action}</string>
</dict>

Is there a possibility that ActionUID become different when the macro is shared and imported ?

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

I don't think ActionUIDs even existed when he wrote that, but I could be wrong.

One warning about scripts: They can't start with a blank line. I forgot about that, and here's the error I got:

const script = 
`
<dict>
	<key>ActionUID</key>
	<integer>492039</integer>
	<key>DisplayToggle</key>
	<false/>
	<key>MacroActionType</key>
	<string>MacroGroupToggle</string>
	<key>MacroGroupUID</key>
	<string>${groupUUID}</string>
	<key>ToggleMode</key>
	<string>${action}</string>
</dict>
`;
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.

const script = 
`<dict>
	<key>ActionUID</key>
	<integer>492039</integer>
	<key>DisplayToggle</key>
	<false/>
	<key>MacroActionType</key>
	<string>MacroGroupToggle</string>
	<key>MacroGroupUID</key>
	<string>${groupUUID}</string>
	<key>ToggleMode</key>
	<string>${action}</string>
</dict>
`;

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.