How to set environment variables for Mac OS X applications

Posted on: Sat, 10 Jan 2009 02:42 By: patrick

Although the typical Mac user, living in the Aqua land of blissful ignorance, usually does not care about environment variables and other such "strange" beasts, it may sometimes become unavoidable having to deal with this stuff from the ninth hell of command line wickedness.

My moment of truth came when I wanted to run the Gimp (the official Mac port can be downloaded from here) in a different language (English) than the default language of my Mac OS X installation (German). For this I had to run Gimp.app using the environment variable LANG set to the value en.

I guess the canonical source for information on how to set environment variables for Mac OS X applications (i.e. .app bundles) can be found in this article on developer.apple.com.

Probably the best/easiest way to edit the environment.plist file (mentioned in the above article) is the very nice (and free) "Environment Variables" preference pane that can be downloaded from rubicode.com. This lets you change environment variables comfortably from within the System Preferences application. However, modifying environment.plist changes the environment for all applications. If you want to make the change apply to only one single application, you have two options, both of which need some manual fiddling:

  1. Single-shot:
    • Open a session in Terminal.app
    • Set the desired environment variable (e.g. "export LANG=en"); note that the variable needs to be exported in order to be inherited by the application
    • Launch the application (e.g. "open /Applications/Gimp.app")
    • VoilĂ , the application inherits the environment from the terminal session
    • You can repeatedly launch applications from the same Terminal.app window, but once you close this window, the environment variable is gone
  2. Persistent:
    • Note: You need to have administration privileges for this because you are going to edit a file from within the /Applications folder
    • Open the Info.plist file located within the application bundle (e.g. "open /Applications/Gimp.app/Contents/Info.plist")
    • Add a top-level key named LSEnvironment which is of type "Dictionary"
    • Add a child key to the dictionary which represents the desired environment variable; the key name/value corresponds to the environment variable's name/value (e.g. key name = "LANG", value = "en")
    • Save the changes back to the Info.plist file
    • From now on, whenever you launch the application in the Finder or from the Dock, the application will run with the correct environment variable set

Note that, for some unknown reason, approach #2 did not work when I tried setting the LANG variable for Gimp.app. Since I am happy with approach #1, though, I did not investigate any further. I leave approach #2 written up as it is, because this is how it is supposed to work according to the official documentation at developer.apple.com (see URL at the top of this post). YMMV.

Topics
Article Styles

Add new comment

The content of this field is kept private and will not be shown publicly.

Filtered HTML

  • Allowed HTML tags: <h1> <pre> <br> <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type='1 A I'> <li> <dl> <dt> <dd> <h2 id='jump-*'> <h3 id> <h4 id> <h5 id> <h6 id>
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.
CAPTCHA This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.