AppleScript to go to Specific Macro in Editor by Name and Group

I know how to go to a specific Macro in the KM Editor if it has a unique name, using AppleScript like this (where I supply the Macro's name as a KM Variable).

set kmInst to system attribute "KMINSTANCE"
tell application "Keyboard Maestro Engine"
set macro1 to getvariable "Local_Add to Macro" instance kmInst
end tell

tell application "Keyboard Maestro"
editMacro macro1
end tell

But does anyone know of a way to specify the Name and the Group the Macro is in?

This reads like there may be two Macros with the same name that exist in two Macro Groups. I don't know if there's a way to specify a Macro Name and its Group, but if there is no way wouldn't one workaround be to specify the macro by using its script ID? If it comes to that, maybe then add a comment into the Applescript indicating the actual Macro name and its Group name.

1 Like

The problem is that this is part of a Macro that generates new Macros by Name and Group. I might generate two Macros with the same Name in two different Groups. And then later I want to go to one of those Macros by specifying its Name and its Group.

If there was a way to gather the UUIDs of all macros with same name in different Groups to a list and then choose the relevant Macro by its Group... that might work but I can't find a mechanic to do that.

Target the Group first:

tell application "Keyboard Maestro"
	editMacro (get id of item 1 of (every macro of macro group "Tests" whose name is "Scratch"))	
end tell

...replacing those literals with variables, and setting those variables via Engine calls as you did above.

3 Likes

Thank you so much @Nige_S - it works brilliantly! I can add that to my particular Macro and my Library of AppleScripts!