Skip navigation
This discussion is archived

logout hooks for dummies

7708 Views 7 Replies Latest reply: Mar 22, 2008 9:30 PM by V.K. RSS
V.K. Level 9 Level 9 (56,120 points)
Currently Being Moderated
Mar 22, 2008 7:23 PM
Could somebody please explain in layman's terms how to set up logout hooks?
I found several recipes on the web all suggesting modifying the loginwindow plist but none of this has worked for me.
PowerBook G4 17'', 1.5GHz, Mac OS X (10.5.2), Mac Pro 2.66GHz, Mac Pro 3.2GHz
  • biovizier Level 5 Level 5 (7,925 points)
    Currently Being Moderated
    Mar 22, 2008 8:41 PM (in response to V.K.)
    Actually, the method of configuring "logout hooks" depends on the OS X version - Apple keeps moving it around so a method for one version may not work on another.

    Since 10.4, the login window hooks go in the "com.apple.loginwindow.plist" file in the "root" account's "Preferences" folder (i.e. "/private/var/root/Library/Preferences"). The property name is 'LoginHook' or 'LogoutHook" respectively for the two types (both are case-sensitive), and the value should be the full path to the script.

    Using the 'defaults' command as "root" is probably the easiest way to set them up, as in:<pre>
    sudo /usr/bin/defaults write com.apple.loginwindow LogoutHook /path/to/script</pre>
    http://docs.info.apple.com/article.html?artnum=301446

    Note that loginwindow hooks run as "root" so the script should be stored in a location such that its entire path is write protected against anyone other than "root". It is also probably a good idea to make sure the script works correctly in "Terminal.app" before letting it run as "root" automatically as a hook.
  • red_menace Level 6 Level 6 (14,315 points)
    Currently Being Moderated
    Mar 22, 2008 8:45 PM (in response to V.K.)
    You could just cheat and use LoginWindow Manager.
    G4 Digital Audio 1.4GHz, Mac OS X (10.4.11), G4 mini 1.4GHz, G3 MiniTower 500MHz (OS9)
  • red_menace Level 6 Level 6 (14,315 points)
    Currently Being Moderated
    Mar 22, 2008 8:59 PM (in response to V.K.)
    Bombich also has some information on their website about running shell scripts at login and logout.
    G4 Digital Audio 1.4GHz, Mac OS X (10.4.11), G4 mini 1.4GHz, G3 MiniTower 500MHz (OS9)
  • biovizier Level 5 Level 5 (7,925 points)
    Currently Being Moderated
    Mar 22, 2008 9:05 PM (in response to V.K.)
    Yes, the commands are more or less equivalent. There are some common gotchas - in the 'defaults' command, include the full path, and don't escape spaces, etc. - rather quote the whole thing.

    Also, since the "hook" always runs as "root", be aware that references to "~" will always point to the "root" account's home folder. I'm not sure what root's 'PATH' is by default either, so make sure all commands in your script include the full path (you should do this anyway for security reasons for commands running as "root").

    There are probably others, but these issues seem to come up fairly frequently...

Actions

More Like This

  • Retrieving data ...

Bookmarked By (0)

Legend

  • This solved my question - 10 points
  • This helped me - 5 points
This site contains user submitted content, comments and opinions and is for informational purposes only. Apple disclaims any and all liability for the acts, omissions and conduct of any third parties in connection with or related to your use of the site. All postings and use of the content on this site are subject to the Apple Support Communities Terms of Use.