Get Current User from root mode?
I am writing a login item and I am trying to find if its possible to get the current user. Lets say, I have logged in with user "Test" and when I execute the exe with root privileges and if I use char *user = getenv("USER"); user is "root". My expected answer is "Test". How can I get it? I don't know if I can put objective c code in login item? Is it possible to NSUserName in login item. NSString *user = NSUserName(); You want the SCDynamicStoreCopyConsoleUser function . QA1133 gives some relevant details and caveats. Login items can be Cocoa applications, so you can use NSUserName() (which is