Export Selected Macro(s) or Action(s) in the Keyboard Maestro Editor as XML to BBEdit

Hey Folks,

Sometimes you just need to see the code of things. :sunglasses:

NOTE: This macro can easily be adapted for TextWrangler by changing “BBEdit” to “TextWrangler” in the Execute an AppleScript action, and it would only take a few different changes to support other text editors.


Selected Macro(s) or Action(s) → Copy XML to BBEdit.kmmacros (4.9 KB)

1 Like

I'm looking for a means to copy the XML of a selected macro without using the Interface Control action(s) below.


I thought this macro provided by Chris would work, but I've been unable to get it to work on Keyboard Maestro 10.1.1 on macOS 12.5. It results with:

This macro displays in a window the XML of any macro that's selected in the KM Editor.

You can change it to place the XML into a KM variable or a clipboard if you wish - that's up to you.

Note: this macro is uploaded in a disabled state.

Test Get Macro XML.kmmacros (2.0 KB)

Click to see macro

1 Like

Hello @KM_Panther

I haven't updated KM yet - still using Version 10.0.2 on Catalina and for me this very handy Macro still works like a charm.

Have you selected any Macro(s) or Action(s) before triggering ??

Greetings from Germany


Guten Tag Tobias,

I've not tried Chris' macro with an action or multiple macros, but it has consistently failed to copy any selected single macro to the clipboard. I'll test with an action.

Hey tiffle,

Your macro successfully adds the XML of the selected macro to my targeted Named Clipboard! If possible, I'd like to have it get the XML of any macro that I provide the name for so I don't need to have the macro previously selected.

Thank you very much

oh another German :slight_smile:
Here it works with multiple Macros and multiple Actions selected.

have you tried adding a little pause after the Copy Action? - maybe this could do the trick.

Another Idea I have is to test the Copy Action using the CLIPBOARDSEED() - Function to see if the Clipboard changes....


OK - so you want to get the XML for any macro whose name you specify?

I've turned my example macro above into a KM subroutine which takes a single input and returns an output as follows:

  • Input: the name of the macro you want to get the XML of
  • Output: the XML of the named macro or an empty string if the macro named does not exist.

I've created a test macro for you to try out the subroutine. Here's the test macro:

Test Get Macro XML By Name.kmmacros (2.6 KB)

Click to see macro

And here is the subroutine:

[SUB] Get Macro XML By Name.kmmacros (2.4 KB)

Click to see macro

Download and install both macros and then enable them both. You might also want to assign a hot key trigger to the test macro. After that, edit the test macro and insert the name of the macro whose XML you want to retrieve. Then run the test macro and it will display either the XML of the macro you specified in a window or a blank window if the macro doesn't exist (maybe you mis-spelled its name).

You can get more sophisticated by sending the output of the subroutine to the clipboard or elsewhere and you could use a Prompt for User Input action to ask the the name of the macro to plug into the subroutine.

That's me for the night now... :yawning_face:

1 Like

Guten Abend Tobia,

I added a delay after the copy action, but still no success. However, I've been able to modify the macro provided by tiffle to get what I needed.

Vielen Danke

Hey tiffle,

I played around with your original macro to get what I needed. I needed to get the XML in the background and without any user interaction and came up with the action below.


I have a couple of macros with the same words in the name and didn't want to have trouble using "name contains...". I now see from your new example macro that you've provided that I could have used "name ="

Many thanks for your inspiration!