Thursday, April 10, 2008

Find the console user on OS X

I do allot of OS X packaging, and I one thing that I have been looking for is a way to identify the current user logged into the console (The GUI). I found the answer in a configuration files for SleepWatcher. "SleepWatcher ...is a command line tool (daemon) for Mac OS X that monitors sleep, wakeup and idleness of a Mac."
echo 'show State:/Users/ConsoleUser' | scutil | awk '/kCGSSessionUserNameKey/ { print $3 }'
echo 'show State:/Users/ConsoleUser' -- Echo a command to scutil
scutil -- Take piped input from echo above.
awk '/kCGSSessionUserNameKey/ { print $3 }' -- Find the line kCGSSessionUserNameKey and print 3rd item (The Username).
scutil -- Manage system configuration parameters. You can find the scutil man page here

No comments: