Using a post-installation Environment variable action is working fine on windows installations, however, it seems to be ignored when installing to OSX. My applications depend on be able to read an environment variable that is set at install time. When I launch my application, it has no knowledge of any environment variables supposedly set up during installation.

How can I set an environment variable in OSX? Can you give me a simple example install that accomplishes this?

asked 21 Jan '13, 18:56

FSNB's gravatar image

accept rate: 0%

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.


answered 22 Jan '13, 17:26

juanjo's gravatar image

juanjo ♦♦
accept rate: 23%

Thanks, works beautifully. One minor change, for anyone else that needs this, I did not need the <![CDATA[ and corresponding ]] tags in the program arguments for defaults. It was not working with them, but when I removed them, it worked

(22 Jan '13, 18:31) FSNB

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?


answered 22 Jan '13, 03:22

juanjo's gravatar image

juanjo ♦♦
accept rate: 23%


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.


answered 22 Jan '13, 11:47

FSNB's gravatar image

accept rate: 0%

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?


answered 22 Jan '13, 13:39

FSNB's gravatar image

accept rate: 0%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported



Asked: 21 Jan '13, 18:56

Seen: 2,740 times

Last updated: 22 Jan '13, 18:31