MacInsomnia

[ Previous Tip ] [ Mac Tips ] [ Next Tip ]


MacInsomnia

The Mac OS is designed to let a computer gracefully sleep automatically and wake quickly. This primarily serves to conserve power. On a laptop running from a battery, this can be critically important. Having the battery run down because a computer wasn't doing anything is a very bad thing. On a desktop, it is a bother because the computer can tend to run up your power bill. Depending on the power that the computer draws and the current electricity rate, the power bill to run a computer all the time can exceed $60/year.

There is a timer that can be set in the System Preferences Energy Saver Preference Pane to allow a Mac to sleep after a set period of no user activity. The key word here is "allow." While the sleep command that a user issues from Apple > Sleep acts nearly immediately and with high reliability, the sleep timer does not force sleep. Even if the timer runs out, it can take several minutes for a properly functioning computer to sleep. After the time runs out, there are any number of things that can still keep the computer awake. Finding these things is the subject of this page.

Generally, if the computer thinks that it is busy, or being used by the local or some remote user, it will stay awake so that it is maximally responsive. Sometimes however, it fools itself and stays awake on it's own even when it should be sleeping. These are some of the things that will keep it awake.

Time Machine. The Time Machine process will hold a computer awake until it finishes. If the sleep timer has run out in the meantime, the computer should sleep shortly after Time Machine finishes.

Spotlight. Spotlight is the feature that allows rapid searches. To perform this task, it examines every disk attached (unless excluded) and builds an index of the disk. This normally happens in real time as the contents of the disks are changed. However, if the index is damaged or it is a disk that hasn't been indexed already, Spotlight can spend hours rummaging through the disk to build an index. Spotlight will also hold the computer awake until it finishes.

Sharing. Sharing, particularly file sharing, will hold a computer awake. If another computer has mounted yours as a shared volume, expect it not to sleep until the remote user ejects yours. Screen sharing can do the same thing. Printer sharing will hold the computer awake for the length of a print job. Internet Sharing will also hold a computer awake all the time. Unless you actually use Internet Sharing, turn it off.

Note that if you have "Wake for Network Access" checked in the Energy Saver Preference Pane, the computer will wake briefly every hour or two to advertise it's presence to the network and then it will go back to sleep, perhaps after only 10 seconds. This is normal. If you don't want to access the computer while it is sleeping, turn this option off.

User Input. Any user input, including any activity from a USB device (like a mouse or keyboard) will reset the sleep timer and prevent the computer from sleeping. Cats are noted for waking computers in the middle of the night by walking on the keyboard.

BlueTooth. BlueTooth devices can also wake a computer unless that capability is suppressed in the BlueTooth Preference Pane, Advanced tab.

Power Nap. Power Nap is a feature enabled only in Mountain Lion for Macs that came with an SSD (Solid State Disk) installed and that have fairly recent firmware. Firmware updates for some older models dating back to 2010 of the MacBook Air and some MacBookPro configurations can enable Power Nap. Power Nap allows a sleeping computer to do some housekeeping tasks while otherwise sleeping. The computer will wake about once an hour, check email and other messaging software and do just one Time Machine backup. This is to be sure that the computer is ready to go, for example, the next morning and that no wake up activities are necessary so that it can be grabbed and taken out of WiFi range without the need to wake it up. Even if Power Nap is enabled when on battery power, File Sharing does not work. This is to prevent some sharing activity from draining a sleeping computer's battery. File Sharing will still work when the computer is sleeping while connected to a charger. Power Nap results in a very light touch on the battery when it operates if it is not plugged in.

Sometimes it isn't obvious that a computer is sleeping at all. Depending on the model of Macintosh, there may be a slowly pulsing indicator light that indicates sleep or maybe some heat on the case, or some fan or disk noise. My mid 2011 iMac does not show much of an indication when it goes to sleep at all. I use a Kill-A-Watt AC power meter to show me if my computer is sleeping or not. A sleeping computer will draw 1 or 2 watts from the wall outlet. One that is not sleeping could be in the range of 11 to 100 or more watts.

A USB hub or USB device with an LED on it can provide a sleep indicator if the computer does not have one. In this case, the LED will go out when the computer sleeps. Note that on SOME laptops, the USB ports one either side CAN act differently. Cut an try to see what works.

If a computer is not sleeping when I think that it should sleep, then I follow these steps to track the problem down.

  1. The first thing to do is launch the Terminal application (in Utilities) and type
    pmset -g

    at the command prompt. If you see a line that says "assertions" or "sleep prevented by" and a number, the number is the process ID (PID) of a process that has declared that the computer should stay awake. Open Activity Monitor (also in Utilities). Select "All Processes" and looks for that PID in the first column. On the same line will be the name of the application or process that is keeping the computer awake.

  2. If Time Machine is on, then turn it off. This prevents Time Machine from interfering with your tests.
  3. Set the sleep timer to 1 minute (aids in testing so that the tests don't take so long)
  4. Let it sit for 15 minutes. Even though the time is set to 1 minute, it may take a while to sleep in a normal case. Lion is particularly troublesome in this case as it doesn't want to sleep for at least 10 extra minutes. Mountain Lion tends to sleep more quickly, if both timers are set to 1 minute, the computer will sleep in two minutes.
  5. If it hasn't slept, unplug all USB, Thunderbolt and Firewire peripherals (except keyboard and mouse)
  6. Let it sit for 15 minutes
  7. If it hasn't slept, turn off all sharing options in the Sharing Preferences Pane. This disables all remote connections.
  8. Let it sit for 15 minutes
  9. If it hasn't slept, log out (this quits all user process)
  10. Let it sit at the login screen for 15 minutes
  11. If if it still hasn't slept, restart the computer (this stops all processes). If you are using Lion or Mountain Lion, uncheck the box on the dialog that you get at shutdown to resume applications.
  12. Let it restart and sit at the login screen for 15 minutes
  13. If it is still not sleeping, restart again but hold the Shift key down until the spinning gear thing shows on the screen as it is rebooting. This causes a "safe" boot. A progress bar may appear on the startup screen. A safe boot will take longer, especially if there is file system damage (a safe boot also triggers a disk directory repair) and it will suppress launching of any apps or other processes if you have anything set in your Login Items pane. It also runs some scripts to do a general system cleanup.
  14. If it still isn't sleeping, reset the SMC (System Management Controller). The procedure for doing this varies from model to model, look at this Knowledge Base article for Intel based computers. See this article for PPC based computers. Then test for sleep again.
  15. If it still isn't sleeping, you can try resetting PRAM (Parameter RAM). Although I have never caught this as a problem, it might have an effect and it won't hurt anything except that some settings my be reset to their defaults. PRAM reset instructions are here.
  16. If it STILL won't sleep, then reinstall the OS and run Software Update to see that all system components are up to date. If you are using Snow Leopard, run the system installer as an Archive and Install. If you are running Lion or Mountain Lion, either download a new Mac OS Installer application from the Mac App Store or boot the Recovery Partition (hold cmd-R at boot) and do an install from there. It will take a while depending on the speed of your internet connection. An OS reinstall by these methods will not damage any user or network settings and it'll leave your documents and applications untouched.

At any of these steps where it starts to sleep, you have found an indicator of what was keeping it awake. Start going back up the list and turning things back on until it is running in a normal state and sleeping. If it starts refusing to sleep again, you've narrowed the problem down. Look to the descriptions above about processes that can suspend sleep to get some guidance as to what specifically might be causing the insomnia.

If you find that it won't sleep when you log back in, there are further steps you can take. At the login window, all user processes are halted. Logging in starts up whatever is in your Login Items or if you are running Lion or Mountain Lion, whatever was running when you logged out. If you had clicked the box to not Resume applications, then only Login Items will be running. One of these is causing the problem. Another way to suppress relaunching of user processes at login is to, immediately after you enter your password, press and hold Shift. This will stop any applications from relaunching at login.

Go to System Preferences > Accounts > (your account) > Login Items and delete everything there, you really don't need this in Lion and ML anyway. Then log back out and if you are running Lion or Mountain Lion, make sure that the box that says to Resume applications is NOT checked. Then log back in and test again.

At this point, the system should be sleeping. If not, then you should create a brand new test account and try it there. If the test account doesn't sleep, but the system sleeps at the login window, then you have a problem that I haven't run across yet.

If the test account, or your account with nothing running, sleeps, then start adding running applications back in a few at a time. If it sleeps, add more. If not, one of the last batch was the problem. Shut off each one in turn and test again. When you find the particular app that is doing it, then you'll have to get an updated version that works or you'll have to remember to quit it when you are done using it.


[ Previous Tip ] [ Mac Tips ] [ Next Tip ]


This page has been accessed hit counter times since Feb 10, 2012

© 2012-2013 George Schreyer
Created Feb 10, 2012
Last Updated March 2, 2013