开发者

Add $PATH variable via Cocoa App

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 bu开发者_StackOverflowtton 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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜