O'Reilly Hacks
oreilly.comO'Reilly NetworkSafari BookshelfConferences Sign In/My Account | View Cart   
Book List Learning Lab PDFs O'Reilly Gear Newsletters Press Room Jobs  



Specifying environment variables for applications launched from Finder
How can application bundles launched from the Mac OS X Finder be supplied with environment variables? Answer - via the file ~/.MacOSX/environment.plist

Contributed by:
Djun Kim
[02/26/04 | Discuss (0) | Link to this hack]

It seems all-too-common to hear users complaining that their Mac OS X application runs from the command line, but bombs when launched from the Finder. A little digging in the crash logs (e.g., ~/Library/Logs/CrashReporter/app.crash.log) reveals that the application cannot find a required dynamic library. The application can start from the command line because the dynamic library can be specified using the environment variable DYLD_LIBRARY_PATH.

I see all kinds of unpleasant hacks suggested, including packaging the required libraries with the application bundle, and symlinking the required libraries in one of the 'standard' locations that dyld searches, e.g,, /usr/lib.

A much more elegant solution, with more general applications, is to specify the environment variables to be passed to all applications launched by the finder. Apple provides a mechanism for this via a special file, ~/.MacOSX/environment.plist (Careful - it's case sensitive, of course). This XML file can be created with the Property List editor, or your favorite text editor. Here's a sample:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
        <key>DYLD_LIBRARY_PATH</key>
        <string>/usr/local/lib:/Developer/qt/lib</string>
</dict>
</plist>

See also: Apple's Developer Connection article at http://developer.apple.com/qa/qa2001/qa1067.html


O'Reilly Home | Privacy Policy

© 2007 O'Reilly Media, Inc.
Website: | Customer Service: | Book issues:

All trademarks and registered trademarks appearing on oreilly.com are the property of their respective owners.