« Archive | Main

GUI Environment Variables on OS X and macOS

With the advent of launchd and user launch agents, setting multiple environment variables that are available to your GUI applications is as simple as creating this plist file ~/Library/LaunchAgents/local.launchd.environment.plist

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
        <key>Label</key>
        <string>local.launchd.environment<</string>
        <key>Disabled</key>
        <false/>
        <key>RunAtLoad</key>
        <true/>
        <key>ProgramArguments</key>
        <array>
            <string>/bin/sh</string>
            <string>-c</string>
            <string>for env in "$@" ; do eval $env ; done</string>
            <string>/bin/sh</string>
            <string>launchctl setenv ANT_HOME /usr/local/apache-ant-1.9.6</string>
            <string>launchctl setenv CATALINA_HOME "$HOME/Projects/apache-tomcat-8.0.24"</string>
        </array>
        <key>StandardErrorPath</key>
        <string>/dev/null</string>
        <key>StandardOutPath</key>
        <string>/dev/null</string>
</dict>
</plist>

You can add as many <string>launchctl setenv ... </string> statements as required, one for each environment variable.