0

My app runs as the root user, but was launched from the regular (Admin) user, e.g. using the sudo command (but not necessarily, i.e. I cannot simply check the env var SUDO_USER, for instance).

How can I determine the user name or its homedir that is logged in to the User Interface session?

Is there a Cocoa, Foundation or CoreFoundation function that can give me that information?

Thomas Tempelmann
  • 11,045
  • 8
  • 74
  • 149

1 Answers1

0

It appears the "HOME" environment variable remains set to the logged-in user, even for apps running under the root user. So, here's how to get the home folder for that user:

NSString *homeDir = NSProcessInfo.processInfo.environment[@"HOME"];
Thomas Tempelmann
  • 11,045
  • 8
  • 74
  • 149