site_archiver@lists.apple.com Delivered-To: darwin-kernel@lists.apple.com Dkim-signature: v=1; a=rsa-sha1; c=relaxed; d=classicalguitar.net; h= subject:mime-version:content-type:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; s= classicalguitar.net; bh=LHmC88iP8wWlheeiI4eku2O5vik=; b=lFzfaPHv epVotwhFg11hOMHn0NNBEns4u9Rwlul2ssqnLcrXDMLtN0xgAM3eZCtO5Zbi1BpW Jr4S+/LYWmcPbL8WMuPX4PpPKuzsyB5MsF/bwcG6Ll+EZqDQdfC50S1eZP8R5puN xTPojx0ccJW3tH+CZ37QzwyEUraJlIz5Y4w= Domainkey-signature: a=rsa-sha1; c=nofws; d=classicalguitar.net; h=subject :mime-version:content-type:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; q=dns; s= classicalguitar.net; b=KRAquclt3G3yaxhq9FuULen7xu9aCBJk7r+/CWHDZ W5jj5W0y1ghSrlPc7ay1V0FpYGgtKBr8LaKir4OYDb/3qPztMgzyYLbtg4yrYEu4 onBEiH/ZvnaYjEelt9CczyMg3/3qNz26tCz1/qvgQ0JSy+tSM1kl7Cjf718Yc5wJ wU= Use IOKit, specifically, IORegisterForSystemPower(). In the callback you provide check for kIOMessageSystemWillPowerOff and kIOMessageSystemWillRestart. p.s. Remember to register the notification port you get back with a run loop or your callback will never get called. On Mar 23, 2011, at 8:51 PM, Antoine Missout wrote:
While AppKit shouldn't be used in a global context daemon, you can always have a user-context agent and use something to communicate between the agent and the daemon (nsmachport...).
But that's a really ugly solution to the problem.
What is the mechanism used by NSWorkspace exactly ?
What is the proper answer to the original question, ie getting the shutdown event in a global context daemon ?
- Antoine
On 2011-03-23, at 17:11, Quinn The Eskimo! wrote:
On 23 Mar 2011, at 18:03, Jerry Krinock wrote:
The suggestion there is to use NSWorkspaceWillPowerOffNotification.
NSWorkspace is not the droid you're looking for. AppKit sends it in response to a 'quit' Apple event that has the 'why?' attribute, implying that the app is being quit by loginwindow in preparation for restart or shutdown. This doesn't really help you.
When you say "started automatically by launchd", do you mean the global system launchd (that is, pid 1) or some per-user launchd? If you're started by the global launchd, you're running in a daemon context and you should not be linking with AppKit (per the rules outlined in Technote 2083 "Daemons and Agents").
<http://developer.apple.com/library/mac/#technotes/tn2005/tn2083.html>
S+E -- Quinn "The Eskimo!" <http://www.apple.com/developer/> Apple Developer Relations, Developer Technical Support, Core OS/Hardware
_______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-kernel mailing list (Darwin-kernel@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-kernel/site_archiver%40lists.a... This email sent to site_archiver@lists.apple.com