Vine And Void Mac OS

Update

While OS X comes with a large number of Unix utilities, those familiar with Linux systems will notice one key component missing: a package manager. Homebrew fills this void. To install Homebrew, open Terminal or your favorite OS X terminal emulator and run $. Nuance abandoned the Mac version once before, and a company named Mac Speech filled the void for a few years. Then Nuance purchased Mac Speech and their Mac product was reborn. But I agree, it is incumbent on Apple to fill the void now.

Technical Q&A QA1340

Q: How can my application get notified when the computer is going to sleep or waking from sleep? How to I prevent sleep?

A: Cocoa (Listing 1) and I/O Kit (Listing 3, Listing 4) can both be used to receive sleep and wake notifications. Cocoa can be used to receive sleep and wake notifications, while I/O Kit can also prevent or delay (Listing 2, Listing 3) idle sleep. However, even with I/O Kit, it is not possible to prevent forced sleep, only delay it.

Note: Mac OS X will sleep in two different situations- forced and idle.

  • Forced sleep occurs when the user takes some sort of direct action to cause the machine to sleep. Closing the lid on a laptop or selecting sleep from the Apple menu both cause forced sleep. The system will also induce forced sleep under certain conditions, for example, a thermal emergency or a low battery.

  • Idle sleep occurs when the machine is unused for a specific period of time configured in the Energy Saver System Preferences.

Listing 1 Installing a Cocoa sleep and wake notification.

Note:IOPMAssertionCreateWithName is new API available in Mac OS X 10.6 Snow Leopard. IOPMAssertionCreateWithName allows an application to return a return a brief string to the user explaining why that application is preventing sleep. If you need to support previous versions of Mac OS X you will need to use the notification based APIs (Listing 3, Listing 4) or the deprecated call IOPMAssertionCreate.

Listing 2 Preventing sleep using I/O Kit in Mac OS X 10.6 Snow Leopard

Listing 3 Installing an I/O Kit sleep/wake notification.

To stop receiving I/O Kit sleep notifications, you need to remove your event source from the application runloop and do a bit of cleanup.

Listing 4 Removing I/O Kit sleep/wake notification handler.


Document Revision History

Vine And Void Mac Os X


DateNotes
2014-01-13

Corrected small bug in message logged in receiveWakeNote

2011-03-01

Updated code to use IOPMAssertionCreateWithName.

2008-08-08

Added information about forced/idle sleep, how to receive sleep/wake notification in Cocoa, and expanded IOKit sample to include wake messages and IOPMAssert.

2005-10-17

Added an example of how to deregister for sleep notifications.

2004-10-25

New document that explains how applications can register and unregister for sleep and wake notifications on Mac OS X.




Copyright © 2014 Apple Inc. All Rights Reserved. Terms of Use Privacy Policy Updated: 2014-01-13

Circle with a line through it

Vine

Learn what to do if your Mac starts up to a circle with a line through it (prohibitory symbol).

Question mark

Learn what to do if your Mac starts up to a question mark.

Vine And Void Mac Os Catalina

Options with a gear icon

Learn what to do if your Mac starts up to Options with a gear icon.

Blank (empty) screen

Learn what to do if your Mac starts up to a blank screen, such as an empty gray, black, or blue screen.

Apple logo

Learn what to do if your Mac starts up to an Apple logo or progress bar.

Globe with alert symbol

A globe with an exclamation point means that your Mac tried to start up from macOS Recovery over the Internet, but couldn't. Learn what to do if your Mac can't start up from macOS Recovery.

Lock icon

If your Mac is using a firmware password, the lock icon appears when you try to start up from another disk or volume, such as an external drive or macOS Recovery. Enter the firmware password to continue.

System lock PIN code

Your Mac asks for a PIN code when it has been remotely locked using Find My. Enter the four-digit or six-digit passcode to continue.

Login window

At the login window, enter your user account password to log in to your Mac. If FileVault is turned on, this also unlocks your disk. You might see a default desktop picture in the background, which might change to your chosen desktop picture when you select your account.

Thunderbolt, USB, or FireWire symbol

A large Thunderbolt , USB , or FireWire symbol against a dark background means that your Mac is in target disk mode.

Vine And Void Mac Os Download

Learn more

Vine And Void Mac Os Update

  • Learn what to do if your Mac displays a message that it restarted because of a problem.
  • When starting up from Windows using Boot Camp, your Mac doesn't show an Apple logo or the other macOS screens in this article.