Terminal 101: Managing Power Settings
Posted 08/13/2012 at 10:00am
| by Cory Bohon
Is your Mac having insomnia issues? Trouble sleeping through the night? Like babies and humans, Macs can get finnicky about sleep patterns and may not shut down, or go to sleep properly. No matter how much you tweak the System Preferences, sometimes it takes a little bit of trickery under the hood to get the Mac going the way it should. We'll show you how to find rogue apps in the background, change the lid closed action, and prevent your Mac from sleeping.
1. Find the Applications Causing Shutdown Issues

Sometimes, varying applications can keep your Mac from shutting down. If you encounter a problem like this, you can use the following command to see which applications are causing the issues:
pmset -g assertions
When you type this command and press enter, you will be presented with a list of “assertion status system-wide.” If, in this list, there is a 1 or more in the “PreventSystemSeep,” then there is an app preventing your Mac from sleeping. You can see which app it is in the “Listed by owning process” list below the assertions listing.
In this list, you can also see if there is a process running in the background, preventing display sleep, or preventing sleep while idle.
2. Change Lid Open/Closed Action

On MacBooks, whenever you close the lid, your computer automatically goes to sleep unless it is connected to an external display. You can change this behavior, however, so that when you close the lid, the Mac doesn’t go to sleep.
To do this, open the Terminal and type the following command:
sudo pmset -a lidwake 0
After entering this command, your Mac will no longer sleep when you close its lid. You can reverse this change and make your Mac behave normally by entering the following command:
sudo pmset -a lidwake 1
3. Prevent Sleep while Idle
Whenever your Mac is idle and the option is set to enable sleep after a certain number of idle minutes, then your Mac will automatically sleep. To prevent your Mac from going to sleep while idle, then type the following command into the Terminal:
sudo pmset powerbutton 0
If you wish to change your Mac back to its normal setting, then issue this command at the terminal prompt:
sudo pmset powerbutton 1
Cory Bohon is a freelance technology writer, indie Mac and iOS developer, and amateur photographer. Follow this article's author, Cory Bohon on Twitter.