George Garside Blog

A place of many ramblings about macOS and development. If you find something useful on here, it's probably an accident.

Where are Keyboard Maestro macros stored?

Keyboard Maestro macros are stored on macOS in a property list file among other preferences. In your home folder, open Library, then Application Support, and finally Keyboard Maestro. This folder contains ‘Keyboard Maestro Macros.plist’, and open it to view how your macros are stored on disk.

The best way to open the file is with Xcode, which can pretty-print the formatting of the file and keep the plist binary data hidden away behind disclosure triangles.

How can I move Keyboard Maestro macros to a new Mac?

Copy ~/Library/Preferences/Keyboard Maestro/Keyboard Maestro Macros.plist to the same location on your new Mac. You can find the ~/Library folder in Finder’s Go menu by holding alt.

If you want to copy other settings, you can include other files in the Keyboard Maestro folder. This might be useful if you want to keep your KM license, otherwise you’ll need to recover your license from Stairways.

How to run a Shell Script using Keyboard Maestro?

Keyboard Maestro has an action to run a Shell Script. This action lets you run a script file or a text script entered into the action’s text field in the edit mode of the macro. The output of the shell script can be shown in a window, in a notification, typed or pasted into the current text field, or saved to a clipboard or variable. This is useful for multiple-step macros where the output of one action is the input of another.

Keyboard Maestro Shell Script

What if my Keyboard Maestro text script output is empty?

Shell Scripts can also take input by the means of variables set in Keyboard Maestro’s preferences, or set by other actions, even in other macros. This is the cause of the shell script action not working, as the variables in Keyboard Maestro are set in environment variables so that the shell script can access them. Environment variables have a maximum size, so if your variables are too large, then the shell script action will stop working, without showing any error. This can be quite confusing as no error is presented to the user. Even the shell script results box doesn’t open and display any output.

Keyboard Maestro Output of Shell Script
  1. Open Keyboard Maestro Editor (click the Keyboard Maestro icon in the menu bar and choose Launch Keyboard Maestro Editor).
  2. Go to Keyboard Maestro → Preferences (⌘,) → Variables.
  3. Select all the variables in the list and delete them with ⌫ or the delete button at the bottom of the window.
Keyboard Maestro Preferences: Variables

That’s it — run your macro again and the action should work! If it breaks again in the future, you can simply repeat this procedure to clear the variable causing the scripts to not run and try again. This also applies to the Execute AppleScript action as the environment variables are set there too so that they can be accessed through “run shell script”.

Leave a Reply

No comments