views:

45

answers:

2

Hello All,

I am very new to the Mac platform and Objective-C in general and in my application I would like to know how to determine that a user is logging out and perform some actions prior to this. Any info or pointers for this will be greatly appreciated.

Regards, -Jim

+1  A: 

Take a look at Receiving Workspace Notifications in this Workspace Services document.

NSWorkspaceWillPowerOffNotification

Posted when the user has requested a logout or that the machine be powered off.

Terry Wilcox
+1  A: 

The official way to put the hook at logging in / logging out is described in these Apple documents Customizing Login and Logout and Tech Note 2228. But I'm afraid that the log-out hook was no longer directly supported.

So, the second best way is to run a headless Cocoa app, and receive a notification from the system using NSWorkspace, see the document and the list of available notifications.

To make a headless Cocoa app, you need to set an entry in its Info.plist called LSUIElement, see here. By setting LSUIElement to be yes, the app don't appear in the dock, but perform various operation in the background.

Yuji
Why does it need to be headless? It works just as well for a regular app.
Terry Wilcox
I thought the original poster wants to detect the logging out in general. I couldn't think of any situation in a standard GUI app where I need to distinguish being quit (`applicationWillTerminate:`) and being logged out. I guess I misread.
Yuji