Getting "KM" Icon Images, and Determining "Default" Macro Name When No Name is Specified

@peternlewis Two questions:

  1. When a macro/group's icon is selected from your list of icons, it's stored in CustomIconData something like:

KMEP-QuitBadge
or
KMEC=Square=KMCOLOR:255,255,255,0=☋=104=0=4=0=KMCOLOR:33,255,255,255

Is there any way for me to get the actual icon image for these types of icons? I'm pretty sure the answer is "no", but I thought I'd ask.

  1. When a macro's name is left blank (or "Untitled Macro"), it appears you give it a name from the first action in the macro. Like this one:

image

Is there any way I can duplicate your logic?

Here's why I ask: As you know, there's no XML key for this macro's Name. I'm working on a Macro Import Manager, and I display the macros that are in a .kmmacros file. It all looks good if the Name keys are present, but having one named "undefined" or even "Untitled Macro" is confusing, since that's not what the user sees in KM:

image

I have a "Help" icon to explain the reason, but it would be nice if I could duplicate your logic.

I suspect I'm SOL here too, but I thought I'd ask.

And you can probably infer why I asked question #1.

Thanks.

I don't believe so, no.

I doubt it.

Yeah, sorry.

The image thing, I could perhaps implement something that converted those strings to images, but I really can't see implementing that I'm afraid.

The name, there is not enough information in the XML to determine what name would be shown for the macro without a whole lot of Keyboard Maestro code and strings - basically the entire macro would have to be processed by Keyboard Maestro to determine what the name would be displayed as.

1 Like

Thanks, Peter. Those answers are exactly what I expected, and I totally understand. And certainly, don't implement some solution for this just for me. I just figured it never hurts to ask.

On the subject of the macro name, you could always include the calculated name as a new key in the XML. But honestly, like I said, it's not something that anyone other than a hacker like me would ever need.

Thanks again!

1 Like

Perhaps use that logic? You could import each "undefined" macro to a temporary Group, get the name (and possibly the icon data) with AS/JXA, then delete the Group.

Feels very clunky to import a macro then delete it so you can choose whether or not to import it... You might find a better way of leveraging KM's own logic.

1 Like

Thanks. I totally thought of doing that, but as you said, it would be "clunky". And honestly, it's not worth it, since a simple "help" button will explain it.

If you've already parsed the import out into a collection of macros it wouldn't be too bad, since you'll only have to work with the "undefined" ones. What you would have to do is change the Group name entry in the XML to match your temporary Group name -- I've assumed myTempMacroGroup, but I think it would be better to generate a UUID.

Then, given the list theMacros where every element is the XML of a macro:

set macroNames to {}
tell application "Keyboard Maestro"
	repeat with eachMacro in theMacros
		importMacros eachMacro with disabled
		copy name of item 1 of (every macro of item 1 of (every macro group whose name is "myTempMacroGroup")) to end of macroNames
		delete every macro of macro group "myTempMacroGroup"
	end repeat
	delete macro group "myTempMacroGroup"
end tell

return macroNames

...spitting out a list of names, ordered as per the original macros.

May not be worth it -- but it was fun trying :wink:

Thanks, and I'm glad you had fun trying. :joy: But that method has visual cues in KM that I don't like. Like I said, it's no big deal.

But I also understand the urge to find something that works. I've had a ton of fun coming up with solutions to stuff like this, while working on this macro. I can live with not figuring this one out, though. :joy:

1 Like