Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

ppc_michael

Guest
Original poster
Apr 26, 2005
1,498
2
Los Angeles, CA
I've been asked to make something that keeps track of when users log in and log out (and other information) in a spreadsheet. The log in part is pretty straightforward, I just place my script in Login Items. But log out is different. Is there something like a "Logout Items" that will execute my script immediately before the user logs out?

Right now they're running 10.3 but I think they'll be moving to 10.4 soon. I hope. So a method for either version would be very appreciated.
 
I don't think so. If you can add something to Login items this is easy to get around. Write a really simple app that has no UI (and no Dock icon which is easy). Your app does nothing apart from log when it is started and then waits. When the system notifies you that the users is about to log out log that and exit.
 
Just to flesh out that advice a bit more.

NSWorkspace is probably something you want to look at, in particular NSWorkspaceWillPowerOffNotification which is posted when the user that launcehd the app logs off (or the machine is shut down).

You will probably want to override NSApp -terminate to stop a nasty user killing your app via the Activity Monitor, although this will not stop a Force Quit.

To stop yourself have in a dock icon you need to use the LSBackgroundOnly plist key.
 
robbieduncan said:
Write a really simple app that has no UI (and no Dock icon which is easy). Your app does nothing apart from log when it is started and then waits. When the system notifies you that the users is about to log out log that and exit.

An alternative and possibly more robust way is to periodically check the unix last command and just parse the output for console connections. last obtains the information from the /var/log/wtmp and /var/log/btmp files. These files are updated and maintained by the unix login process.

Ultimately all you need is a simple program that calls last and extracts the necessary information from the output of last and puts the results into your spreadsheet file. Then, set up a cron job that runs once a day at 3am or such like. The cron job should simply call your logging program.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.