How do you set environment variables in OSX




  • Avatar

    Can you paste the code you are using to add the variable? In which OS X version are you testing it? Is you application (the one that expects some variables to be defined, not the installer) an application bundle or a binary?

  • Avatar


    I use


    This same code works on the windows release.

    I am building my installer in windows, and installing it on OSX 10.8.2, I am using Installbuilder Pro 8.5.1

    The application that would use the variable is a .app bundle installed with the installbuilder tools. It is started from the Dock.

    The environment variable does work in the Terminal utility, and if I use "open /Applications/.../" from the terminal, the environment variable is available. The only failure is when the application is started by clicking the the dock or with spotlight.

  • Avatar

    Okay, I have figured out that I need to modify my App bundle's info.plist xml file. So the new question is, how do I add a new value to an XML file?

    For example,

    ?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "">
    <plist version="1.0">
                <string>Copyright IBM Corp. and others 2002, 2010. All rights reserved.</string>

    This file is going to need the ${installDir} installbuilder variable. How would I add an additional key value within the dict key using installbuilder?

  • Avatar

    If you are not already defining the LSEnvironment key, you could use the below (please note you should skip the .plist extension):

      defaults write LSEnvironment '<dict><key>MY_ENV_VAR</key><string>MY_ENV_VALUE</string></dict>' 
      plutil -convert xml1

    Using a runProgram:

    <runProgram program="defaults">
       <programArguments><![CDATA[write LSEnvironment '<dict><key>MY_ENV_VAR</key><string>MY_ENV_VALUE</string></dict>']]></programArgument>
    <runProgram program="plutil">
       <programArguments>-convert xml1</programArgument>

    Or you could simply include a placeholder in you app Info.plist and substitute it using the <substitute> action.

Please sign in to leave a comment.