Skip navigation.
 
mlRe: Setting tcsh env vars for Cocoa app context?
FROM : John Labovitz
DATE : Wed Nov 17 20:26:28 2004

> So, each app invoked via double-click inherits what loginwindow.app
> has, and/or loginwindow.app calls an execve() and sets certain vars
> for child processes. Bottom line is (I guess) that the basic list is
> hard-coded at some level.


Looks that way.  If you open loginwindow.app/Contents/MacOS/loginwindow
in a text editor, and search for something like "PATH" or "SHELL",
you'll see the preceding (dunno why) string seems to be the value that
it's using for that environment variable.  Actually, you can get a good
idea of all the environment variables that loginwindow.app sets by
looking at the strings in that part of the executable.

> Because I want my app to be run by any user on our systems, I've made
> my app generate, execute, and delete temporary shell scripts in /tmp.
> From within those scripts I can reference and run all of the special
> installed binaries in /usr/local/lib and other places by adding those
> paths to the local PATH var in the script.


Writing temp files is always a pretty bad idea, especially if
executable -- if not for security purposes then just for lack of
cleanliness. ;)

I didn't catch the earlier part of this discussion, so I'm not totally
clear on what you're trying to do.

But howabout if you have two applications, rather than one; the first
one simply sets up the environment for the second, launches that app,
then goes away.  Like this:

   // app 1

   int main (int argc, const char * argv[]) {
       //...initialize...

       NSString *launchPath = ...path to real application (could be inside
this bundle!)...

       NSTask *app2 = [[NSTask alloc] init];
       [app2 setEnvironment:[NSDictionary
dictionaryWithObjectsAndKeys:@"foo", @"TESTVAR", nil]];
       [app2 setLaunchPath:launchPath];
       // other set...: methods here as necessary; see NSTask docs
       [app2 launch];

       return 0;
   }

At this point, app1 will have exited, but app2 will still be running,
with the custom environment as specified in the dictionary in the
setEnvironment: method.  (I tried this out as a Foundation tool, not as
a full Cocoa app; things might work differently.)

This might not be totally seamless in terms of the GUI; you might want
to make the first app a faceless application, which I don't remember
how to do.

--
John Labovitz Consulting, LLC
http://mac.johnlabovitz.com
<email_removed>
AIM/iChat: jslabovitz
+1 503.949.3492

Related mailsAuthorDate
mlSetting tcsh env vars for Cocoa app context? Alex Majora Nov 11, 22:14
mlRe: Setting tcsh env vars for Cocoa app context? Alex Majora Nov 12, 01:54
mlRe: Setting tcsh env vars for Cocoa app context? Daniel Eggert Nov 12, 11:41
mlRe: Setting tcsh env vars for Cocoa app context? Alex Majora Nov 12, 18:00
mlRe: Setting tcsh env vars for Cocoa app context? elijah wright Nov 12, 18:26
mlRe: Setting tcsh env vars for Cocoa app context? Alex Majora Nov 12, 19:53
mlRe: Setting tcsh env vars for Cocoa app context? Tom Harrington Nov 12, 20:26
mlRe: Setting tcsh env vars for Cocoa app context? Daniel Eggert Nov 17, 15:01
mlRe: Setting tcsh env vars for Cocoa app context? Alex Majora Nov 17, 17:51
mlRe: Setting tcsh env vars for Cocoa app context? John Labovitz Nov 17, 20:26