Run Commands at Shutdown

namaste

Registered
I would like to have an Applescript or if need be a shell script run at shutdown and/or logout that will do some basic house cleaning operations. Is this possible? How would I go about this?
.
 
To run a shell script on a user's logout, you need to edit /etc/ttys. Near the top, there is a line that looks like (note, this is actually one line in the file)

Code:
console "/System/Library/CoreServices/loginwindow.app/loginwindow"
vt100 on secure window=/System/Library/CoreServices/WindowServer 
onoption="/usr/libexec/getty std.9600"

which you change. To run, for example, /usr/local/bin/userlogout when a user logs out, add a -LogoutHook (again, this should be just one line in /etc/ttys):

Code:
console "/System/Library/CoreServices/loginwindow.app/loginwindow
-LogoutHook /usr/local/bin/userlogout" vt100 on secure
window=/System/Library/CoreServices/WindowServer 
onoption="/usr/libexec/getty std.9600"
 
OK, now I've got something that works, but it's not as pretty as I'd like. What I have is an Applescript that launches as a stay open app at login. I've put an on quit handler in it that will do certain things when it receives the quit event from the sytem at shutdown/reboot. Now my problem is that I don't like the script icon showing up in the dock the whole time I'm logged in.

Is there a way to have an application not put an icon in the dock?
 
Originally posted by testuser
blb,
I'm not sure if this answers his question.

I believe namaste wants a script to run when one chooses "Log out" from the Finder, or when one chooses "Sleep" or "Shutdown". I believe that this is one of the things that still needs to be implemented in OS X.

If I'm not mistaken, I think editing ttys will only allow running a script when someone logs out of a Terminal or SSH session on your Mac.

The change I posted was against the ttys file, yes, but note the switch -LogoutHook is against loginwindow.app, which is run on the local console, for the GUI login. So when you logout from Finder, this runs. I agree that shutdown procedures are yet to be implemented, however.
 
Originally posted by testuser
...
Never Mind; I should really print out that System Overview and read it cover to cover some time!

Yup, that one PDF has quite a few useful little tidbits buried inside. One of the few reasons I use Acrobat Reader instead of Preview to read it is for doing searches...

For those who don't have it, mine is at /Developer/Documentation/Essentials/SystemOverview/SystemOverview.pdf which suggests it comes with the devtools but is more of an admin book. It should be part of a default install in my opinion.
 
Back
Top