Tuesday, December 14, 2010

User's environment in OS X

The question arises: how to get access to the user's path on OS X. Stack Overflow does not disappoint (here):


// gcc -o test test.m -framework Foundation -fobjc-gc-only
// .test
#import <Foundation/Foundation.h>

int main (int argc, const char* argv[]) {
NSDictionary *eD = [[NSProcessInfo processInfo] environment];
NSLog(@"%@",[eD description]);
return 0;
}



$ ./test
2010-12-14 11:56:23.002 test[650:903] {
"Apple_PubSub_Socket_Render" = "/tmp/launch-bvNjPH/Render";
"COMMAND_MODE" = unix2003;
DISPLAY = "/tmp/launch-cWN8zD/org.x:0";
HOME = "/Users/telliott_admin";
LANG = "en_US.UTF-8";
LOGNAME = "telliott_admin";
OLDPWD = "/Users/telliott_admin";
PATH = "/Users/telliott_admin/bin/:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin";
PWD = "/Users/telliott_admin/Desktop";
SHELL = "/bin/bash";
SHLVL = 1;
TERM = "xterm-color";
"TERM_PROGRAM" = "Apple_Terminal";
"TERM_PROGRAM_VERSION" = 273;
TMPDIR = "/var/folders/rK/rK4-yxtZHUGADBsC5YPRk++++TI/-Tmp-/";
USER = "telliott_admin";
"_" = "./test";
"__CF_USER_TEXT_ENCODING" = "0x1F5:0:0";
}