Apple - How to set PATH for Finder-launched applications

If you are on 10.7 and not 10.8, the solution below works well:

I had the same problem with eclipse, but now I've added e.g. the following to my .bash_profile and then it worked.

export PATH=some_path:another_path
launchctl setenv PATH $PATH

In case you want to leave the original path intact use

p=$(launchctl getenv PATH)
launchctl setenv PATH /my/new/path:$p

instead (or just launchctl setenv PATH /my/new/path:$(launchctl getenv PATH)).

Note: Changing the launchctl PATH will not take effect until the Dock is "restarted". A new Dock process will automatically start after the current one is killed with the command:

killall Dock

On OS X 10.10 Yosemite, I used this command:

sudo launchctl config user path <my path setting>

Be aware that his sets the launchtl PATH for all users. This worked well for my use case. Note that you'll be asked to reboot your machine for the effects to take hold.

You must restart all applications for this to have effect. (It doesn't apply to applications that are reopened at login after rebooting.) (Thanks @Brecht Machiels.)


To answer you question to your 'new' problem, I've decided to write another answer - because it is easier to explain with samples.

One way to load the environment variables on startup of your tool (IDE) of choice is like it can be done with eclipse - I think there must be a similar structure in your tool (IDE) too.

How it can be done in eclipse - https://stackoverflow.com/questions/829749/launch-mac-eclipse-with-environment-variables-set

(slightly re-written about the environment variables)

Create an empty text file called "eclipse.sh" in the Eclipse application bundle directory /Applications/Eclipse.app/Contents/MacOS

Open the eclipse.sh in a text editor and enter the following contents:

#!/bin/sh

. ~/.bash_profile

logger "$(dirname \"$0\")/eclipse"

exec "$(dirname \"$0\")/eclipse" "$@"

In the Terminal set the executable flag of the shell script eclipse.sh, i.e.:

chmod +x /Applications/Eclipse.app/Contents/MacOS/eclipse.sh

Open the Eclipse.app Info.plist and change the value for the key CFBundleExecutable from eclipse to eclipse.sh.

MacOS X does not automatically detect that the Eclipse.app's Info.plist has changed. Therefore you need to force update the LaunchService database in the Terminal by using the lsregister command:

/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -v -f /Applications/Eclipse.app

The next time you launch Eclipse.app from the Dock or from the Finder the environment variables should be set.

Tags:

Macos

Path

Finder