Add PATH Environment Variable to launchd Scripts

Recently I was having an issue with Node.js not being detected in my PATH with a Python script executed by launchd. This was bizarre to me for a couple of reasons.

First, I’ve been using launchd for awhile now, and any LaunchAgents run under my profile usually has detected anything in my path, including Homebrew installed binaries.

Second, when testing the script via Terminal it worked perfectly.

After reading the available launchd keys, I discovered you can add an EnvironmentVariable with a list of your PATHs that will be executed before the ProgramArguments key.

It worked perfectly, and since it seems to be little used, I thought I’d post it here. Here is an example of the format you want to use in your launchd item: