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

FSNB
6336
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 yourApp.app/Contents/Info LSEnvironment '<dict><key>MY_ENV_VAR</key><string>MY_ENV_VALUE</string></dict>' 
  plutil -convert xml1 yourApp.app/Contents/Info.plist

Using a runProgram:

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

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

link

answered 22 Jan '13, 17:26

juanjo's gravatar image

juanjo ♦♦
5.8k413
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?

link

answered 22 Jan '13, 03:22

juanjo's gravatar image

juanjo ♦♦
5.8k413
accept rate: 23%

Hello,

I use

<addEnvironmentVariable>
   <name>NEWPATH</name>
   <scope>system</scope>
   <value>${installdir}</value>
</addEnvironmentVariable>

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/.../myapp.app" 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.

link

answered 22 Jan '13, 11:47

FSNB's gravatar image

FSNB
6336
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" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
    <dict>
        <key>CFBundleGetInfoString</key>
            <string>Copyright IBM Corp. and others 2002, 2010. All rights reserved.</string>
        <key>CFBundleIdentifier</key>
            <string>org.myAPp</string>
    </dict>
</plist>

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

link

answered 22 Jan '13, 13:39

FSNB's gravatar image

FSNB
6336
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

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "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

Tags:

×92
×41
×14

Asked: 21 Jan '13, 18:56

Seen: 2,740 times

Last updated: 22 Jan '13, 18:31