
Signature
Donald S. Hall, Ph.D.
Apps & More Software Design, Inc.
http://www.appsandmore.com
don at appsandmore dot com
"Schedule your scripts with Script Timer"
> By the way, does anyone know why admin privileges are needed to create a
> user specific logout hook? I had no trouble adding 'LogoutHook' to
> ~/Library/Preferences/com.apple.loginwindow.plist. (But, it didn't seem
> to cause my script to run when I logged out...)
Login and logout hooks are intended to be used by a system administrator
to tailor a system.
Given that
a) these run with root privileges (see
<http://docs.info.apple.com/article.html?artnum=301446>: "Unlike
Startup Items that open when a user logs in, a login hook is a script
that executes as root."
b) (on my system) ~/Library/Preferences/com.apple.loginwindow.plist is
writable by me
c) I can not find documentation ever mentioning user-specific login hooks
I strongly suspect that it is not possible to specify login or logout
hooks in ~/Library/Preferences/com.apple.loginwindow.plist.
So, if you want to run code with user privileges at login, use a startup
item.
AFAIK, there is no functionality for running things at logout with user
privileges yet. The easy workaround would be to run a background-only
daemon from a startup item, and to have this daemon call the logout
script when the application is asked to exit. Warning: depending on the
way you do this, it might interfere with the logout process (for
example, the Finder might put up an alert "shutdown item has cancelled
the logout process")
Reinder
Donald Hall - 27 Sep 2006 05:45 GMT
> > By the way, does anyone know why admin privileges are needed to create a
> > user specific logout hook? I had no trouble adding 'LogoutHook' to
[quoted text clipped - 31 lines]
>
> Reinder
Reinder,
Thanks for taking the time to reply, and for the document reference. I
think I have a better understanding of why root privileges are needed.
There are a number of references to running logout hooks on the web -
for example, a way to mute the startup chime. They all use "sudo
defaults write com.apple.loginwindow LogoutHook /path/to/script". For
some reason this fails to work for me. (My test script works fine
otherwise - I don't think it is the problem.)
I already tried your suggestion of running a background program that
would run a script when it was sent a quit message. Unfortunately, while
the system sends a quit message to all running programs, it only waits
for a reply from foreground apps - background apps are immediately
killed. I tried having my background app start up a foreground app that
would simply run the script, but that too is cut off at the knees - I
guess because it is a child of the background app.
Regards,
Don

Signature
Donald S. Hall, Ph.D.
Apps & More Software Design, Inc.
http://www.appsandmore.com
don at appsandmore dot com
"Schedule your scripts with Script Timer"