[launchd-dev] ~/LaunchAgent + KeepAlive=true = Login Jail

Quinn eskimo1 at apple.com
Tue Jan 29 02:45:47 PST 2008

At 16:25 +0000 28/1/08, Hamish Allan wrote:
>You might try listening for distributed notifications associated with
>shutdown and restart:
>(I found these on Leopard with Notification Watcher:

These are not considered supported API.  Worse yet, determining the 
state of login window by tracking these events is tricky.

>If you get a Quit after receiving either of the first two but without
>having received the third, it's a Quit for a Shutdown rather than a
>Quit just for the sake of quitting.

A better solution is to look at the kAEWhyAmIBeingLoggedOutAttr 
('why?') attribute of the kAEQuitApplication ('quit') Apple event. 
If you're being quit by loginwindow, this will contain one of four 
different codes indicating why (kAEQuitAll, kAEShutDown, kAERestart, 
kAEReallyLogOut).  If you're being quit by the user (or by an 
AppleScript or any other 'quit' Apple event mechanism), this 
attribute won't be present.

I could've sworn that this attribute was publicly documented, but I 
looked long and hard and couldn't find anything.  Well, it /should/ 
be publicly documented IMHO <rdar://problem/5712210>.

Quinn "The Eskimo!"                    <http://www.apple.com/developer/>
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

More information about the launchd-dev mailing list