Writing a macro to navigate to smart groups, but they don't seem to have a UUID

Hello,

I quickly navigate between KM macro groups using the macro below.

It works very well . I created a hotkey for a KM "Go To" palette, and that palette contains a series of macros navigating to different groups. It saves a lot of time compared with scrolling and clicking around.

My problem is that only "normal" macro groups seem to have a UUID, not smart groups. For smart groups, I tried to take the "long route" by going through the menu as per below. It works but is slow.

My question is do smart macro groups have a UUID, or is there an equivalent apple script to navigate to them ?

Go To Global Macro Group.kmmacros (2.5 KB)

Yes. A couple of thoughts...

This AppleScript will give you the name and id of the selected group. Just make sure you select a group first:

tell application "Keyboard Maestro"
	set MySelection to selection -- get selection
	set sGroup to item 1 of MySelection -- get first item of selection
	set sGroupID to id of sGroup -- get ID of selected group
	set sGroupName to name of sGroup -- get name of selected group
end tell

You can reference a group by name or id:

tell application "Keyboard Maestro"
	activate
	editMacro "Group Name" -- name of the group instead of id 31244526-8D7B-46EC-AAOA-DE3DA5857689 in your screen shot
end tell

Screen Shot 2022-08-14 at 7.57.48 AM

thanks very much !

how would I copy results to the clipboard ?

You're welcome :+1:

Lots of options. One way would be to return the given variable, and set the KM Execute AppleScript action to "save result to clipboard":

Or return both the ID and Name:

return "ID: " & sGroupID & " Name: " & sGroupName

You could also save the script variables as KM variables.

1 Like

This AppleScript is very helpful because just today I wanted to write one to retrieve the names of every macro inside a smart group... but for some reason even though this script will give me the smart group's UUID, when I use that in the following AppleScript I get an error...

AppleScript to get list of macros names (click to expand/collapse)
--for debugging: test macros
set macroGroupID to "0E6959AD-478C-493F-B4CF-C55BC7E97037" --Test Macros
set macroGroupName to "Test Macros"

--for debugging: Smart Group: macOS Shortcuts
set macroGroupID to "7B1B3AD5-B099-47F5-8C50-3C33D6556717"
set macroGroupName to "Smart Group: macOS Shortcuts"

tell application "Keyboard Maestro"
	
	tell its macro group macroGroupName
		set MacroIdList to id of every macro
		set MacroNameList to name of every macro
	end tell
	
end tell
Screenshot: Script Debugger error message (click to expand/collapse)

That AppleScript works to retrieve the names of the macros inside my "Test Macros" group... but fails when I try to do the same for a smart group.

Any idea why I am not able to retrieve the names of a smart groups macros if I have the group's UUID?

Any help is appreciated, thanks in advance!

-Chris

That's a tough one. I suspect it is because each macro "belongs" to a macro group, not a smart group. If you look at the xml for a given macro, you will see its macro group. So I am guessing it has to do with that underlying data, not how they are displayed in the editor.

1 Like

If you look at the AS dictionary:

macro group n : A macro group.
elements
contains macros; contained by application.

...but

smart group n : A smart group.
elements
contained by application.

The data just isn't available.

Bit of a kludge, but select a macro in your smart group, then ⌘A to select them all, then run

tell application "Keyboard Maestro"
	return name of (every macro whose selected is true)
end tell
1 Like

works perfectly. thank you

OK thanks

Yea I figured that was the issue. Not really worth investing more time in since my need for this was very minimal. Thanks for the info!