Know when the system slept in the Extra menu?

I designed the Extra menu for the Mac, but I would like to know if the device slept using the Extra menu. I implemented a snooze function, but since this is a temporary method, it is rather unreliable. Any advice and recommendations would be greatly appreciated!

Thanks!

+4
source share
1 answer

You probably want to check NSWorkspaceWillSleepNotification in NSWorkspace .
The trick is that you need to register for notifications at the NSWorkspace notificationCenter, not the default. See Technical Q & A QA1340 .

Code example:

 - (void) receiveSleepNote: (NSNotification*) note { NSLog(@"receiveSleepNote: %@", [note name]); } - (void) fileNotifications { // These notifications are filed on NSWorkspace notification center, not the default // notification center. You will not receive sleep/wake notifications if you file // with the default notification center. [[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self selector:@selector(receiveSleepNote:) name: NSWorkspaceWillSleepNotification object:nil]; } 
+6
source

All Articles