OS X: How to run a program with a specific PATH?

One of challenges many developers face is to be able to maintain different (old) products, built with various versions of the development tools, some quite obsolete.

The right answer to this challenge is to have different virtual machines with the complete environment. Unfortunately, due to crazy licensing issues, currently running Mac OS X as a virtual guest on a Mac OS X host is not allowed (according to some rumours, Lion will change this).

The next choice is to keep multiple versions of the development tools installed in different folders, but in this case extra care should be taken to avoid messing the PATH.

Once multiple version of the same tool are present in the filesystem, the safest way is to avoid adding any of them to the PATH, and start each tool with a specific PATH.

For example, we would like to start a certain version of Eclipse with a certain version of the cross toolchain:

export PATH=$PATH:/usr/local/CrossPack-AVR/bin
$HOME/Developer/Eclipses/eclipse-3.6-cdt-m512/eclipse

One solution would be to create a script file and give it a name ending in .command. This makes the script clickable in Finder, but has the disadvantage of  leaving a Terminal window around.

A very convenient solution is to use an AppleScript, and save it as an Application (.app).

 The new application behaves exactly as any application, i.e. clicking it in Finder executes the embedded code and, in this case, starts the Eclipse with the given PATH.

About Liviu Ionescu (ilg)
Hi! My name is Liviu Ionescu (ilg, ilegeul or eunete for colleagues and friends) and I’m a senior IT engineer. Or should I say a real programmer?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: