Exporting multiple macros for version control

I have several hundred macros that I’d like to track in a single git repo, but KM doesn’t seem to want to export them in a batch as individual files. Any trick to this, or is it a missing feature?

I wrote this macro to export macros individually. Basically this macro just loops an n-amount of times and calls the export feature. Maybe there’s something that can be done with AppleScript/JXA but I haven’t had time to check that out yet.

1 Like

There is no direct support in Keyboard Maestro for exporting macros as individual files, but it would be relatively straight forward XML parsing to take an export of all macros and break it into exports for each macro files.

I think this will quickly do what you want:

The PHP script hasn't been updated in several years but when I last used it (a couple months ago) it worked great. I used it along with another macro I wrote that adds a markdown file and images of the macros so that you can peruse a set of macros without importing them. I'll post if anyone is interested.

Awesome, thanks for that, @Chauncey. Do you have a quick “how-to” for using that script? It looks like it’s Ruby, not PHP, and is returning

kmmexport.rb:12:in `export': undefined method `[]' for nil:NilClass (NoMethodError)
    from kmmexport.rb:51:in `<main>'".

Answering my own question: The Preferences path on line 9 has to be changed to Application Support. However, I’m getting a new error – @Chauncey or anyone, any ideas?:

/Library/Ruby/Gems/2.0.0/gems/plist-3.1.0/lib/plist/parser.rb:91:in `scan': invalid byte sequence in UTF-8 (ArgumentError)
from /Library/Ruby/Gems/2.0.0/gems/plist-3.1.0/lib/plist/parser.rb:91:in `parse'
from /Library/Ruby/Gems/2.0.0/gems/plist-3.1.0/lib/plist/parser.rb:29:in `parse_xml'
from kmmexport.rb:22:in `kmm_file'
from kmmexport.rb:12:in `export'
from kmmexport.rb:51:in `<main>'

Whoops! I gave you a link for the original Ruby script. Check out the PHP version here:

It's quite simple to implement. Just copy/paste the script and call it like so:

For the Ruby script, you’ll likely need to use v1.9.3 (or perhaps earlier) since it was created 4 years ago. Too bad there’s no .ruby-version.

Ah, great, thanks for clarifying, @Chauncey. Sorry for being a nuisance, but copy/pasting that generates a warning and fatal error around:

require_once(lib/CFPropertyList/CFPropertyList.php): failed to open stream: No such file or directory in /private/var/folders/lc/qg4sy6_n2zsfybb9yc7pcb400000gn/T/Keyboard-Maestro-Script-CB008F5F-1434-44B8-827D-53F5FE69CB3E on line 10

Any ideas?

Not a nuisance at all! The php script requires the dependancy CFPropertyList.php. Since it wasn’t available, you received the error you mentioned. Because I haven’t used this export feature in a while I forgot about that part.

If you were to clone the original repo, you’d actually need to do a git clone --recursive to bring in a submodule (but the README.md doesn’t mention this).

However, I have good news! I went ahead and forked the old repo and added instructions to correctly use the php script. I also added the ability to export to a formatted markdown file with image previews of each macro.

Check it out.

1 Like