OSX: Environment variables in GUI programs
From the site pointed in the previous post in this blog, I finally understood how to setup env vars for GUI apps in OSX! This was driving me nuts, but things are starting to make sense again! 😉
There is also an official Apple tech article where this info is covered.
Environment variables in GUI programs
A GUI program will inherit the environment variables from the process that started it. So if you launch a GUI program from the command-line, it will inherit the environment variables of the shell where you launched it.
But if you launched the GUI program via Finder (by double-clicking) or the Dock (or some other mechanism in OS X’s GUI environment), it will inherit the environment variables of the “loginwindow” process. To set such environment variables, follow the procedure explained in this Apple TechNote.
You need to create a folder named “.MacOSX” in your home folder (note that since there is a dot at the beginning of the folder name, it won’t be visible to a simple ‘ls’ – you would need to use ‘ls -a’) and then create a file named “environment.plist” in the ~/.MacOSX folder. Put the definitions of the environment variables that you want defined for all GUI programs in that plist file using a format like the following example:
DYLD_LIBRARY_PATH String /Applications/MATLAB_R2007b/bin/maci:/Applications/MATLAB_R2007b/sys/os/maci:/usr/lib:/usr/local/lib
PATH String /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin
(You can use the “Property List Editor” that comes with Apple’s developer tools or a 3rd-party plist editor – or just an ordinary text editor if you are careful to get the format correct. You can also install a Pref Pane for setting environment variables, known as RCEnvironment).