Using the macOS "defaults" command to read KM's data files

I discovered this shell command which shows all of Keyboard Maestro's settings. I never knew until today that the "defaults" command could work on app names or on plist files. Here's how to use it with the app name for Keyboard Maestro:

defaults read -app Keyboard\ Maestro

Here's how to read a specific key (MouseGetCountdown) from that file:

defaults read -app Keyboard\ Maestro "MouseGetCountdown"

Sadly, there are very few interesting keys in that file, and modifying them when Keyboard Maestro is running may not be useful because KM (either the Editor or the Engine) can overwrite your modifications, or can fail to notice the changes until you restart KM. The only keys that may be of interest to average KM users are:

  • Appearance
  • LargeText
  • DisplayWelcomeWindow
  • MouseGetCountdown

(I was hoping to see the value of the inactivity timer that saves the KM macro plist file when the user is inactive for 2 seconds. I wanted to increase that value.)

Somewhat more interesting is that you can use the defaults command to open the Keyboard Maestro "Macro file", using this command: (it's a fairly large file, as it contains all your macros. In my case it's 172 MB.)

defaults read ~/Library/Application\ Support/Keyboard\ Maestro/Keyboard\ Maestro\ Macros.plist

Even more interesting is that you can convert the KM macros plist file into a text readable file like this: (I'm saving the file into the /tmp folder in this example.)

Keep in mind that this file can be quite large, especially since the plutil command "expands" it.

When I started looking into this my goal was to read the Macros plist file into a JSON variable. I didn't succeed because XML is not JSON compliant, and also because reading all your macros into a variable could end up resulting in a kind of infinite loop (i.e., each time you load the macros file into a variable, your macro file will probably triple in size.)

So this research didn't achieve my goals today, but it's worth documenting it here.

2 Likes

You can use BBEdit to open plist files directly.

DO NOT MODIFY any of these while Keyboard Maestro or Keyboard Maestro Engine is running.

Many of the settings in the Keyboard Maestro preferences are described in Preferences.

3 Likes