Script KM to create macros

Is there a method to tell KM to create a new macro?

Here’s what I’m trying to do.

I have a rather long list of servers that I connect to via SSH. I use various user names for these servers. The servers are also grouped per their intended purpose (database, web server, middleware). I’ve used Python to generate server.command files that will open a terminal session to that server with the proper user. That same Python script generates an applescipt text file for each server. The applescript has the advantage of allowing me to open a new session in a tab.

I want those applescript text files to be executed by KM. Yes, I know I can create these KM macros one by one, but there are a LOT of servers here. I would prefer to script the KM macro creation.

For each applescript file:
read the contents
put the contents in a new KM, named after the file name

You can use:

tell app “Keyboard Maestro” to importMacros “[xml]”

The xml should be data in the same format as an exported macro. Essentially an array of macros (technically, an array of macro groups each containing a single macro).

So create a couple template macros and export it, and then look at the XML and determine what you need to adjust to create the desired macros.

Note that this is not a feature I think anyone has used, but it is there specifically for cases like this. So it is highly untested, but should work. If you can’t get it working, I’m happy to look in to it further.


This looks straight forward. I’ll try tomorrow.

This is awesome! I now have a macro that builds new Insert Code Snippet macros based on the current selection. The only problem is that when the new macro is imported, the palette the macro is on is hidden. I put a show palette action after the Execute AppleScript action that imports the macro, but it still doesn't show up.

What can I add to this macro to restore the palette's visibility?

What are the settings of your macro group?

When is the palette supposed to be open?

Disable that macro, and change your configuration on the Macro Group “SuperTalk” to show a palette until Presumably that macro group is limited to those two applications as well.

Then Keyboard Maestro will show it in either of those applications.

1 Like

That did it... Thanks!