Tell me more ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

Apps launched via Finder seem to not respect the PATH as set in .bash_profile. So when I try to run code from an IDE (Intellij) I no longer have access to programs in /usr/local/bin, which is normally added to my path in the Terminal.

Apparently .MacOSX/environment.plist used to be the way to do this, but it no longer works in Lion.

How can I set the PATH for Finder-launched applications?

share|improve this question
Are you sure that your accepted solution works on 10.8? – Sorin Sbarnea Sep 11 '12 at 14:40

3 Answers

up vote 5 down vote accepted

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)).

share|improve this answer
1  
I ended up using: "launchctl setenv PATH $PATH". Appending the existing launchctl path via "$p" ends up repeating the path each time you open a shell. – Caffeine Coma May 20 '12 at 13:06
Also worth noting- until you have started up a shell (via Terminal) launchctl will have the default path, and the customized path will not be available. This drove me a little batty trying to debug things until I figured out what was going on. If I started Intellij before opening a shell, the path would be wrong. Seems like the real solution here is to configure launchctl on a system-wide basis, and not via login shell by some user. – Caffeine Coma May 20 '12 at 13:16
This does not work on OS X 10.8 - tried with Eclipse and IntelliJ - running set|grep PATH from them will always return PATH=/usr/bin:/bin:/usr/sbin:/sbin – Sorin Sbarnea Sep 11 '12 at 14:39
It is still working for me on OS X 10.8 with eclipse, so I don't know what you are doing wrong ?? – Rene Larsen Sep 11 '12 at 22:02
1  
Doesn't work for my either (10.8.1) – patrix Sep 12 '12 at 4:42
show 2 more comments

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 - http://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/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/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/Eclipse.app

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

share|improve this answer
This technique also works for Rubymine once you adjust the path. I found it didn't at first, but then realised that my settings were in .profile, not .bash_profile. – Matt Gibson Nov 16 '12 at 13:29

On Mountain Lion all the /etc/paths and /etc/launchd.conf editing doesn't take any effect!

Apple's Developer Forums say:

"Change the Info.plist of the .app itself to contain an "LSEnvironment" dictionary with the environment variables you want.

~/.MacOSX/environment.plist is no longer supported."

So I directly edited the app's Info.plist (right click on "AppName.app" (in this case SourceTree) and then "Show package contents")

Show Package Contents

and added a new key/dict pair called:

<key>LSEnvironment</key>
<dict>
     <key>PATH</key>
     <string>/Users/flori/.rvm/gems/ruby-1.9.3-p362/bin:/Users/flori/.rvm/gems/ruby-1.9.3-p362@global/bin:/Users/flori/.rvm/rubies/ruby-1.9.3-p326/bin:/Users/flori/.rvm/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:</string>
</dict>

(see: LaunchServicesKeys Documentation at Apple)

enter image description here

now the App (in my case SourceTree) uses the given path and works with git 1.9.3 :-)

PS: Of course you have to adjust the Path entry to your specific path needs.

share|improve this answer
Is this true? I see lots of posts with contradictory information, some of which are clearly old, but some of which seems recent. I don't even have (on 10.8.2) a /etc/launchd.conf anyway. Presumably, even if the rules not state that apps should use their Info.plist files for paths, they could still be using other files -- /etc/launchd.conf, /etc/paths/, or /etc/paths.d/*, or `~/.MacOSX/environment.plist. Is it safe to say then that, in practice, paths for GUI apps in Mountain Lion could be set in any of these files? – raxacoricofallapatorius Feb 3 at 17:47

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.