Important: This document may not represent best practices for current development. Links to downloads and other resources may no longer be valid.
Setting environment variables for user processes
Q: How do I set environment for all processes launched by a specific user?
A: It is actually a fairly simple process to set environment variables for processes launched by a specific user.
There is a special environment file which loginwindow searches for each time a user logs in. The environment file is:
~/.MacOSX/environment.plist (be careful it's case sensitive). Where '~' is the home directory of the user we are interested in. You will have to create the .MacOSX directory yourself using terminal (by typing
mkdir .MacOSX). You will also have to create the environment file yourself. The environment file is actually in XML/plist format (make sure to add the .plist extension to the end of the filename or this won't work). An example environment file is shown below. The file was created using Xcode.
Here the environment variables
MrX are set to MyValue and 1 respectively, every time that specific user logs in. Note that the key class must be string. If any other class is used the key will not be recognized by loginwindow. You can confirm the environment variables have been set as expected by typing
set into terminal.
Cocoa applications can retrieve environment variables in NSDictionary form by using the NSProcessInfo class contained in the Foundation framework.
Document Revision History
Reflects plist creation in Xcode rather than Property List Editor.
New document that tells how to set environment variables for user processes.