views:

2132

answers:

2

My company provides an eclipse based development environment which needs some environment variables setting up for the underlying toolchain so multiple versions can be installed concurrently and not take over the system.

I want to provide an icon in finder or the dock which sets these then launches eclipse so customers cannot accidentally launch eclipse without the environment being set. This is what I have tried so far:

  1. Setting environment in Info.plist for eclipse:

    This should be a nice way to do it but I cannot make it add to the existing path (like export PATH=/myapp/bin:$PATH).

  2. bash script wrapping eclipse:

    I created a bash script called eclipse.command to set the environment then launch eclipse. This opens a terminal window as well as the eclipse icon and allows people to "Keep on dock" for the bare eclipse. I cannot put eclipse.command on the dock as it is not an application.

  3. Applescript wrapping eclipse.command:

    An Applescript wrapper around eclipse.command makes it look like an app and prevents the terminal window appearing. Unfortunately I now get a dock icon for the applescript and one for eclipse so can still keep the bare eclipse on the dock.

Any suggestions? Am I going about this in completely the wrong way?

+1  A: 

Take a look at a related question: Environment variables in Mac OS X.

Basically, this involves the creation of a ~/.MacOSX/environment.plist file.

mouviciel
+5  A: 

There is an alternate solution which involves replacing the executable that is run by MacOS X when the user launches the Eclipse application with a shell wrapper that sets up the environment.

Create an empty text file called "eclipse.sh" in the Eclipse application bundle directory /Applications/eclipse/Eclipse.app/Contents/MacOS.

Open the eclipse.sh in a text editor an enter the following contents:

#!/bin/sh

export ENV_VAR1=value
export ENV_VAR2=value

logger "`dirname \"$0\"`/eclipse"

exec "`dirname \"$0\"`/eclipse" $@

In the example ENV_VAR1 and ENV_VAR2 are the environment variables being set up. These variables will be visible to processes launched from within Eclipse. The logger command will just log the path of the eclipse executable to the system.log as a debugging aid.

In the Terminal set the executable flag of the shell script eclipse.sh, i.e.:

chmod +x /Applications/eclipse/Eclipse.app/Contents/MacOS/eclipse.sh

Open the Eclipse.app Info.plist and change the value for the key CFBundleExecutable from eclipse to eclipse.sh.

MacOS X does not automatically detect that the Eclipse.app's Info.plist has changed. Therefore you need to force update the LaunchService database in the Terminal by using the lsregister command:

/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -v -f /Applications/eclipse/Eclipse.app

The next time you launch Eclipse.app from the Dock or from the Finder the environment variables should be set.

sakra
Simply the best option by a wide margin! Thank you very much, works flawlessly!!
Alexandre L Telles