Created
December 5, 2017 16:26
-
-
Save joncardasis/2c46c062f8450b96bb1e571950b26bf7 to your computer and use it in GitHub Desktop.
Retrieve the console username of the user running a Swift program
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SystemConfiguration | |
/** | |
Retrieve the console username of the user running the program. | |
Will be the same result as a `whoami` command. | |
*/ | |
public func systemConsoleUsername() -> String? { | |
var uid: uid_t = 0 | |
var gid: gid_t = 0 | |
return SCDynamicStoreCopyConsoleUser(nil, &uid, &gid) as String? | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment