How can I get an Action for a specific ActionId from the KM Editor, in either AS or JXA?

As far as I can tell, when using JXA or AppleScript, there's no (easy) way to get an Action object for a specific Action ID.

I mean, you can get a Macro object for a specific UUID, and I suppose in theory you could traverse its actions until you found the one you were looking for, but that's harder than you might think, since Actions can be contained in other actions.

Anyone got any ideas? @peternlewis?

I believe that is correct, in part because actions exist within that nested structure so it's challenging to return one without the other existing.

Do you know the macro concerned before you start? If not you can quickly narrow the field:

set actionID to "16239351"

tell application "Keyboard Maestro"
	every macro whose xml contains actionID
end tell

...which works regardless of nesting level. Obviously it can get you a few false positives, but you can shake those out as you process further.

You could then (waves hands vaguely) either recursively process the actions of each macro or parse the XML...

You've got an Action ID -- what's your end goal here?

This bit of AppleScript does that and is simple enough to be modified easily:

2 Likes

Agreed. Except KM knows how to do it, otherwise "selectAction" wouldn't work.

Yes, I know the macro, but thanks for that. :slight_smile:

Thanks, that's awesome, and it might lead me to the solution I need. I'll post a different topic on the JXA code I've been working on which is kind of similar to that, except I'm having issues.

2 Likes

I wave my hands vaguely, and @tiffle drops the answer in our laps...

I must try that more often!

2 Likes

If you find time to convert that AppleScript to JavaScript that would be awesome :grinning:

I don't think your hands need any help Nigel!!

1 Like

I promise to do just that, once you help me solve a specific problem :rofl: , which I've posted here:

Yes, but Keyboard Maestro has all the macros and actions already - AppleScript does not, and I'm not sure I can create them all (in AppleScript land) to make the result work. Probably it's possible, but AppleScript land is an entertaining place to mess around with.

1 Like

Thanks Peter, that makes sense. And don't bother with solving this - I have a solution that work now.

Thanks again.