After I sold my old laptop and bought a MacBook Pro, I was constantly annoyed at how long it took to go to sleep. When I close the lid, that usually means I'm about to toss my Mac in my bag and go… but the fact that the hard drive keeps spinning for 20 seconds makes me hesitant to do the whole "toss it in the bag" thing. Why did it take so long for Mr. Sandman to arrive? Was my MacBook busy counting electric sheep?
Well, actually it was busy saving its RAM to the hard drive. Which seems silly, because it keeps the RAM powered while it sleeps. It only saves the RAM to disk because Apple is concerned that you might leave your laptop in sleep mode for so long that it runs out of power, forcing it to read the RAM back from disk when it powers back up again. Thank you for your concern, Apple, but what if a faster sleep is more important to me than saving the RAM to disk?
Apple doesn’t provide any sleep vs. hibernation control in its preferences, but this page says how to change hibernation modes on the command line. And it’s dirt simple!
- sudo pmset -a hibernatemode 0
The above command makes my MacBook go to sleep instantaneously when I close the lid. I can grab it and go, without worrying about jarring the hard drive. And I only have to run this command once, not every time I put my Mac to sleep.
The "hibernatemode" actually has several settings, for which I have created aliases in my .bash_profile:
- alias hibernatefast="sudo pmset -a hibernatemode 0"
- alias hibernatefull="sudo pmset -a hibernatemode 5"
- alias hibernatesafe="sudo pmset -a hibernatemode 7"
Here, "hibernatefast" is the immediate sleep, the way that I like best; "hibernatefull" is the true hibernate mode that saves RAM to disk and turns off the power, which is what I need when boarding an airplane; "hibernatesafe" is the Apple default combined sleep/hibernate mode.