tags:

views:

32

answers:

2

I'm trying to write a Cocoa app that makes it easier for Android developers on Macs to create Android apps.

When a user presses a button on the app, I want it to add a certain directory to the environmental $PATH variable on the Mac.

Is there another way to do this via Cocoa instead of opening up the .bash_profile file and adding the path manually?

Thanks for any help in advance.

+2  A: 

You could use the getenv() and setenv() standard C library calls to change the $PATH for the application itself. This change will only be seen by your application and its child processes.

In other words, the $PATH change will not be global. If you want to do that, you will have to change the startup files.

James Roth
A: 

You can set the environment for all user processes by writing a dictionary file to Home/.MacOSX/environment.plist. However, this only takes place after a logout.

I think that the best way to achieve your goal will be to launch the program in question as a subprocess of your own application using NSTask, setting its environment by sending the NSTask object a setEnvironment: message prior to launching it.

Peter Hosey