Firstly, PlistBuddy is a command-line tool, located in /usr/libexec. This tool supports the editing of Mac plist files. The plist file that you can setup to include env variables should be located in $HOME/.MacOSX/environment.plist. This is not a default file so you'll have to create it. PlistBuddy is a great place to start.
Some points I learned the hard way on the use of PlistBuddy and the $HOME/MacOSX/environment.plist file.
- If you include you HOME env in $HOME/.MacOSX/environment.plist make sure it is correct. The reason is that should you set it to the incorrect directory then applicants that store important files in your $HOME directory with not be able to find them and may fail to work altogether. Safari for example will likely start to display a dialog on its startup that reports it is unable to locate your keychain. (Note: that setting up your $HOME env here is not really needed as it is setup already for you by other system scripts when you login. I did because that little bit of information I was not aware of at the time.)
- You can't use variable shorthand, such as $HOME, within the values of the env keys you will likely create inside of $HOME/.MacOSX/environment.plist. I didn't like this but such is the case. This means a great deal more work in setting up long variables such as a Java CLASSPATH env.
- If you also add an identical env in our .bash_profile file that variable will overwrite or hide the one in $HOME/.MacOSX/environment.plist. So be carefull.
To use PlistBuddy follow these simple steps:
- Startup the Mac Terminal app.
- Start PlistBuddy up via the following command-line:
- /usr/libexec/PlistBuddy ~/.MacOSX/environment.plist -- If the file does not already exist than PlistBuddy will create it.
- To see the applications help enter 'help' at the PlistBuddy command line prompt.
- To 'Add' a Key/Value pair use the 'Add' command as in:
- Add :JAVA_HOME string /Library/Java/Home
- To 'Delete' the same key use this command:
- Delete JAVA_HOME
- To view a key's value use 'Print' is in:
- Print JAVA_HOME
Here is a very good PDF on the use of various unix tools available on the Mac OS X platform. Included within this PDF is some coverage on the use of PlistBuddy and another tool you will also likely find use for is 'plutil'.
Enjoy,
Philip