Unix Environment Variables for Mac OS X Applications

Mac OS X applications that are launched by the Finder (e.g., by double clicking the associated.app folder) do not see environment variable settings you make for your Unix shell, say from a Terminal window or in your .bash_profile file. For these applications you must put your settings in a property list file that Mac OS X reads when you log in. That file is ~/.MacOSX/environment.plist

You can edit the property list with vi or emacs, as I typically do, or with the Property List Editor application from /Developer/Applications/Utilities if you have the (free) Apple developer tools installed on your system. The resulting environment.plist file will look something like this:

<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
         "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
    <dict>
        <key>XERCESCROOT</key>
        <string>~/Development/xerces-c</string>
    </dict>
</plist>

The changes will be visible to your applications the next time you log in.

You can also use the defaults program to edit your environment settings. E.g.,

$ defaults write ~/.MacOSX/environment XERCESCROOT -string '~/Development/xerces-c'
$ defaults read ~/.MacOSX/environment
{
XERCESCROOT = "~/Development/xerces-c";
}

But this will leave your environment.plist file in binary form that you cannot edit directly with vi or emacs but instead you will have to use the Property List Editor application to edit. That is unless you run plutil on the file to convert it back to ASCII XML.

This is documented clearly on the Apple Developer Website, but as a long-time Unix developer it stymied me for a while when I migrated a project from plain GNU Makefiles to a full-blown Xcode project and I could not get Xcode to use the environment variable settings I had in my .bash_profile file.