From my macOS GUI app (written in Swift and C) how do I find out the interactive user name for the login session where my process is running?
I know that I can use getuid()
and geteiud()
to get the user ID that the process is running under, but that doesn't work if the GUI app is elevated to root with the call to AuthorizationExecuteWithPrivileges
. In that case I still get the root user, when I need the name of the interactive user whose desktop the app is running in.
macOS has a special function for that: SCDynamicStoreCopyConsoleUser. Here's the example how you can use it.