Create a PATH Environment Variable for Keyboard Maestro and Add /usr/local/bin to the Default Path

Hey Folks,

Did you know that Keyboard Maestro by default only sees a very few of the Unix executables on your system?

So under normal circumstances you may have to call an exe by its full path in an Execute a Shell Script action like this:

/usr/local/bin/AudioSwitcher -a

That's cumbersome and hard to read.

It's much nicer to be able to write (and read):

AudioSwitcher -a

Fortunately Peter has allowed us a means to set Keyboard Maestro's shell environment variables – see the Execute a Shell Script section of the wiki for more information.

The appended macro will add the /usr/local/bin/ directory to Keyboard Maestro's PATH variable, and it will be stored in ENV_PATH. You can see this in Keyboard Maestro's preferences' variable panel.

If you already have customized your ENV_PATH variable the macro will exit and leave it alone.

If you use the MacPorts package manager for Unix executables you might want to use this command, instead of the one in the macro. It will add the MacPorts directories and the /usr/local/bin/ directory.

echo opt/local/bin:/opt/local/sbin:/usr/local/bin:$PATH;

Since this alters your Keyboard Maestro environment I've left off a trigger. The easiest way to run it in Keyboard Maestro 8 is with Cmd-Shift-R in the editor.

Download: Create a PATH Environment Variable in Keyboard Maestro and Add -usr-local-bin to the Default Path.kmmacros (6.8 KB)

Macro Image

If somehow you manage to screw things up you can just delete the variable ENV_PATH from Keyboard Maestro's preferences' variable panel and start over.



Hey Folks,

Rather than going to the trouble of downloading, importing, and changing Chris' macro, I find it simpler to add ENV_PATH manually.

The KM Wiki provides excellent instructions here:

It is easy to check for and add a KM Variable in the Variable tab of the KM Editor Preferences:

  1. Press . to open KM's Preferences.
  2. Click on the Plus button to add a Variable.
  3. Enter the Variable Name. "ENV_PATH" in this case:
    • IF the variable already exists, its value is shown in the Value panel.
      Just click there to change the value.
    • IF not, press RETURN, then enter the value.

Choose whichever method works best for you: macro or manual.