Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

logout hooks for dummies

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

Posted on Mar 22, 2008 7:23 PM

Reply
Question marked as Best reply

Posted on Mar 22, 2008 8:41 PM

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.
7 replies
Question marked as Best reply

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.

Mar 22, 2008 8:49 PM in response to biovizier

Thanks.
biovizier wrote:
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.

I run 10.5.2. does this make a difference to what you suggest?

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.





This is exactly what i tried earlier except I used

sudo defaults write com.apple.loginwindow LogoutHook /path/to/script

isn't that the same thing? I tried out the script first and it works. I'll try again with your command.

Message was edited by: V.K.

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...

logout hooks for dummies

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.