Logout Items?

Discussion in 'macOS' started by ppc_michael, Apr 24, 2006.

  1. ppc_michael Guest

    ppc_michael

    Joined:
    Apr 26, 2005
    Location:
    Los Angeles, CA
    #1
    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.
     
  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    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.
     
  3. ppc_michael thread starter Guest

    ppc_michael

    Joined:
    Apr 26, 2005
    Location:
    Los Angeles, CA
  4. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #4
    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.
     
  5. mrichmon macrumors 6502a

    Joined:
    Jun 17, 2003
    #5
    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.
     

Share This Page