I share all the KM macros I made.
There are two folders there: macros and palettes. And inside there there is a little more nesting like app and global inside app.
To add the macros that are now on GitHub, I had to manually select the macro library in KM sidebar and export them one by one. Like for example this 1Password
library here:
And then clicking Export Macros...
menu bar action:
I did that for every single one of the libraries I had and then manually sorted the files into folders. Where 1Password/2Do and other single app macro groups went into app folder. And macro groups that are global in scope that I often prefix with something went into global folder.
The same thing for palettes too as they are just KM macro groups too.
My question then is how can I automate this process of exporting all the relevant macro groups from KM into the appropriate files on my system so I can commit them.
Another issue is that I don't want to export all macro groups. Some groups like ones that start with per:
prefix (stands for 'personal') or these two groups:
I want to keep. Because they contain private info that I don't want to share. Everything else however I want to share and I need a macro that when pressed will export all the macro groups except the few that are private so I can commit them. Without having to manually click through the sidebar and export macro groups one by one.
Is this possible to do? I would appreciate any help on this. Thank you.
It is definitely possible, but it will take some work to develop an AppleScript to do so.
However, you have many examples in this forum to help you with parts of the script.
Here's a script outline to get you started. The rest is up to you.
You may want to try Script Debugger 7.
SD7 now comes with a 20-day free trial, and then will gracefully downgrade to SD7 Lite (which is still much better than Script Editor).
AppleScript Outline to Export Macros in Groups
tell application "Keyboard Maestro"
set mgList to macro groups whose name does not start with "_"
repeat with oMG in mgList
set mgName to name of oMG
### Commands to Add ###
# set mgFolder to POSIX path of create folder for MG
set macroList to name of every macro in oMG
repeat with oMacro in macroList
log oMacro
# Using UI scripting because KM does NOT have an "export macro" command:
# Select oMacro in macro panel
# Export Macro using KM Menu File > Export Macros...
# Set the export folder to mgFolder
end repeat
end repeat
end tell
Good luck.
Examples of Tools in Script Debugger 7
SD7 Explore Panel
SD7 Dictionary View
Export Macro Groups as individual macros
Preview
DOWNLOAD
I have two versions: One that exports a group and another that exports the whole library. And since my website is still on hiatus, here you go:
Export Groups (individual macros)
Version: 1.2
Date: 2018/05/31 10:30 CEST
By: Patrick Welker
Web: http://rocketink.net
Select a macro group or a macro inside a group in the editor. Run this macro. The editor will loop through all macros, export them individually (named with their actual name) and export them in a folder on your Desktop (named after the group).
OPTIONS:
- You can set a custom export path and whether you'd also like to export a screen shot of the macro in the SETTINGS:
- You can add custom renaming rules to the macro (see magenta colored actions in the screen shot). This is useful in case you named some of your groups with characters that don't work well in the operation system, c.f. my " :: Keyboard Maestro Palette" gets renamed to " Keyboard Maestro Palette" – I got rid of all double colons. Also "Foo: Bar" would end up as "Foo - Bar":
NOTE: While the macro does it's magic, don't switch apps. Just sit tight and let it do its thing. This is not a sophisticated solution, it's just your average Frankenstein's GUI automation monster.
Export Library (indivdual macros, grouped)
Version: 1.2
Date: 2018/05/31 10:30 CEST
By: Patrick Welker
Web: http://rocketink.net
This macro attempts to export all macro groups as folders with the individual macros as .kmmacros
files. Folder and macros are named after their actual name.
The companion macro "Export Groups (individual macros)" has to be installed.
OPTIONS:
- You can set a custom export path and whether you'd also like to export a screen shot of the macro in the SETTINGS:
If you want to use these settings, Global_Configuration
has to be set to "1", otherwise the settings from the companion macro will be used.
- You can set the amount of smart folders to skip. Defaults to 1 (i.e. skipping the "All" group).
NOTE: If the macro fails on calculating the correct amount of groups you have, deactivate the "Automatic Version" and switch to the "Manual Version" _(where you simple enter how many groups you want to export. In this case you also have to specify a group as a starting point for the macro).
While the macro does it's magic, don't switch apps. Just sit tight and let it do its thing. This is not a sophisticated solution, it's just your average Frankenstein's GUI automation monster.
4 Likes