Valid Macro Names?

@peternlewis or anyone else who knows: What are the rules for valid macro names?

The reason I ask is that I'm working on a little macro that allows you to rename selected macros based on regex patterns. It was originally just a throw-away for something I wanted to do quickly, but I got to thinking it might be a good thing to upload, so I started working to make it more bullet-proof.

Since I do the rename using the Editor's "Macro" automation object, I didn't want to try to change the name to something invalid, like a string with a \n in it.

That got me to wondering what else I should check for. I searched the wiki trying to find a definition of valid macro name rules, but couldn't find any.

Any help would be appreciated.

Not sure it helps -- but you can include a tab in the name:

tell application "Keyboard Maestro"
	set name of macro id (item 1 of (get selectedMacros)) to ("foo" & tab & "bar")
end tell

And you can use a linefeed, at least with AS -- KM simply treats it as a null character:

tell application "Keyboard Maestro"
	selectedMacros
		--> {"F7661F0D-9381-4FC4-BE21-BF2E0353E902"}
	get name of macro id "F7661F0D-9381-4FC4-BE21-BF2E0353E902"
		--> "foo1bar"
	selectedMacros
		--> {"F7661F0D-9381-4FC4-BE21-BF2E0353E902"}
	set name of macro id "F7661F0D-9381-4FC4-BE21-BF2E0353E902" to "foo
bar"
	selectedMacros
		--> {"F7661F0D-9381-4FC4-BE21-BF2E0353E902"}
	get name of macro id "F7661F0D-9381-4FC4-BE21-BF2E0353E902"
		--> "foobar"
end tell
Result:
"foobar"

Which makes me think that you're covered if using AS or JXA to rename, although there's a risk of duplicate names.

1 Like

Thanks for that!

Any character that does not match regex \R is allowed.

3 Likes

Thanks!