Is There a Way to Script Adding Favorite Actions?

@peternlewis Is there a way to add a favorite action using AppleScript or JXA? Because if so, I can automate importing favorites from KMFAM to the native favorites.

If not I can probably still find a kludgy way of doing it, but I thought I'd ask first. Thanks.

1 Like

I don't think so, but there probably should be.


Hey Dan, just have to say first off - Incredible job with KMFAM. You and @peternlewis do incredible work, it definitely does not go unnoticed - huuuuuge thanks to you both!!!

Secondly, I've been scratching my head over this for a while now - I've tried copying and editing some of your KMFAM "dependencies", which led me to try and figure out some HTML editing, which then led me to some frustrations, which somehow led me here.

Was just wondering - I'm trying to make more fully automated workflows, and part of that is loading up some of my favorite actions and dynamically filling certain fields within them automatically. Did you ever manage to fully add a favorite action to a script without user input? If so, if you could be so kind as to lend me any help, I'd really appreciate it quite a lot! Thank you!!! :slight_smile:

I'm talking off the top of my head here, but if you set up the action the way you'd like it, then you can use "Copy as XML" to copy it. It's just text, so you can save it in a variable, or a named clipboard, or whatever.

Then next time you want to use it, you should be able to just do a "paste", assuming you have the editor focused correctly.

If you want to change something in the action before you paste, you can do a search-and-replace of the XML. Just put some token text you can find that won't match anything else in the XML. Like "$$ReplaceThis$$".


Hi, @EricHuergo. Albeit in a limited context, I'm doing this in a macro I recently shared: Insert Action to Check Variable(s), v2.0

1 Like

Here's a direct example of performing the desired task:

Keyboard Maestro Editor ⇢ Paste Dated Attribution Action v5.00 Macro - #11 by ccstone


Dan, you absolutely nailed it! That was absolutely what I needed for my attempts at getting KM to 'script itself'!!! Thank you so much!!!

1 Like

@_jims, while "Insert Action to Check Variable(s), v2.0" didn't necessarily work for what I was trying to accomplish at the moment I have to say that that is some very clever work you've done! Thank you anyways for the share, will definitely be looking into it later! : )

1 Like

Just had a look at it and that looks incredibly promising - especially for some JS or other code formatting further down the road!!! For my current use case however, @DanThomas's note of being able to paste XML from a named clipboard seemed to work best!

Thank you everyone for your incredible support! : )

1 Like

You can't just paste XML and have it turn back into a KM object – you have to finesse the clipboard with AppleScriptObjC.

You can simply copy an object to a named clipboard and paste that, but it is an object – not text.

If you'll look at my macro you'll see it is composing an action from XML and then creating the new action in the selected macro with AppleScript.

1 Like

You should look at @DanThomas' famous and elegant KMFAM macro.

Dan's macro is absolutely superb and eminently useful.

My macro methodology is excellent for creating macros and/or actions on the fly with custom features.

You can use a variation of my method to work with your own favorites group by creating macros in a group with one or more actions and then using AppleScript to read them and insert them and change their attributes if desired.

Keyboard Maestro is remarkably flexible.


Hi @EricHuergo. Yes, that macro has a unique function, but if you look at the actions near the bottom, you’ll see that they are used to do what you mentioned.

BTW, @ccstone helped me with the necessary AppleScript syntax. He's an absolute wizard and he tends to do a lot of his magic in Execute AppleScript actions.

In contrast, to avoid breaking large glass objects :wink:, I tend to use AppleScript only when necessary. So in my macro, you will see that I jump between AppleScript and other Keyboard Maestro native actions.


If you get my KMET macro set, it has a macro called "[µKMET Sub-Macro] Set Clipboard to Objects Text". You pass it the XML, and it puts it on the clipboard in the proper format for pasting into KM.