List of macros in a group

G'day

I'm using the following Apple Script to get the names of every macro in a group named Timers

tell application "Keyboard Maestro"
	set macroList to {}
	
	repeat with g in macro groups
		if name of g is "Timers" then
			repeat with m in macros of g
				set end of macroList to name of m
			end repeat
		end if
	end repeat
end tell

-- convert list to newline-delimited string
set AppleScript's text item delimiters to linefeed
set macroText to macroList as text
set AppleScript's text item delimiters to ""

tell application "Keyboard Maestro Engine"
	setvariable "timersList" to macroText
end tell

Could this be done with native Keyboard Maestro?

As a start, you can extract it from the plist but I suspect that will be a fair amount of work using native Keyboard Maestro actions but I could be wrong.

Although not Keyboard Maestro actions you use the following command in a Shell Script to read from the plist which may be a bit easier noting you need to change every occurrence of __Utilities to teh desired macro group. The said your AppleScript is not awful in terms of complexity.

Run in terminal or a Keyboard Maestro shells script:

plutil -convert xml1 -o - ~/Library/Application\ Support/Keyboard\ Maestro/Keyboard\ Maestro\ Macros.plist | xmllint --xpath "//dict[string='__Utilities']/key[text()='Macros']/following-sibling::array[1]/dict/key[text()='Name']/following-sibling::string[1]/text()" - | sed 's/<\/string>/&\
/g' | sort -f
1 Like

That's very inefficient. Much quicker:

...where the AS is:

set AppleScript's text item delimiters to linefeed
tell application "Keyboard Maestro" to return (name of every macro of macro group "Tests") as text

Change the name of the macro group to suit.

The downside of using AS, of course, is that the Editor must be open. If that's a problem then you can use a shell utility as @Joel suggests. Or, since KM's macro plist is "flat" (no nesting of groups) with consistent indenting, you can get away with text searching.

1 Like

Indeed it is :slight_smile:

I didn't know that. Thanks for the heads up!

Cheers

Keith

To clarify -- when I say "must be open", if you run the script and the Editor isn't open then tell application "Keyboard Maestro" will launch the Editor so the enclosed commands can be executed.