I have a Mac that I share with my kids. I've given each of them their own account and use parental controls to control what they can access. This gives me a lot of control, but does not tell me everything I want to know. I was also curious about their usage habits, such as what time of day they login and how long they typically are on the computer, so I needed a way to track that data.
After reading about login hooks in OS X, and doing a little more research on the web, I came up with a few simple scripts that can be run at login and logout to solve my problem. With these scripts, any time anyone logs into or out of the computer, a log entry will be created. If you keep your log file in the /var/log directory, then you can easily view the file using the Console application.
So here's how I did it.
#!/bin/bash
# login script
username=${1}
timestamp=`date ''+%m-%d-%Y_%H:%M:%S''`
computer=`hostname`
logfile="/var/log/usertracking.log"
echo $username," "$timestamp," "$computer," login" >> "$logfile"
And here's the logout script:
#!/bin/bash
# logout script
username=${1}
timestamp=`date ''+%m-%d-%Y_%H:%M:%S''`
computer=`hostname`
logfile="/var/log/usertracking.log"
echo $username," "$timestamp," "$computer," logout" >> "$logfile"
$ sudo chown a+x /usr/local/bin/loginscript
$ sudo chown a+x /usr/local/bin/logoutscript $ sudo defaults write com.apple.loginwindow \
LoginHook /usr/local/bin/loginscript
$ sudo defaults write com.apple.loginwindow \
LogoutHook /usr/local/bin/logoutscript $ sudo defaults delete com.apple.loginwindow LoginHook
$ sudo defaults delete com.apple.loginwindow LogoutHook
$ sudo rm /usr/local/bin/loginscript
$ sudo rm /usr/local/bin/logoutscript
$ sudo rm /var/log/usertracking.log
You can also track who logs into your computer via file sharing over your network, as explained in this hint. You can also completely disable the ability for guests to login via file sharing, as explained in this hint.
Mac OS X Hints
http://hints.macworld.com/article.php?story=2006081701162739