Problem


I have been searching for ways for Mac OS X to behave the same as Windows when it comes down to hibernation. Mac OS X has this concept of "Sleep" and "Shutdown".

By default, "Sleep" will turn the computer off but my MacBook Pro will still have the white light, switching between dim and bright. In this case, you cannot totally switch off your MacBook Pro as you would like to do in Windows.

However, if you "Sleep" using your laptop battery, once the battery runs out, MacBook Pro is smart enough to save all contents in your RAM to hard disk. This is called a "Safe Sleep".





Wish


Wouldn't it be nice if we could choose to hibernate whenever we want so that if we are not using the laptop for a few hours, instead of putting the laptop to "Sleep", which will still drain the battery, we can "hibernate" the laptop and restore our applications (as it is) when we start it up again.

Solution


Macworld has an article that contains comprehensive information about this. Here is the summary.
  • First find out what is the current setting of your sleep mode, using:
> pmset -g | grep hibernate


This will tell you which sleep mode you are currently on. The following displays different sleep mode:


0 - Legacy sleep mode. It will save everything to RAM upon sleeping but does not support "Safe Sleep". Very fast sleep.
1 - Legacy "Safe Sleep". This is the "Safe Sleep". Everything your laptop goes into sleep, it will save everything to harddisk. Slow on Sleep and Startup.
3 - Default. As described above, when sleeping, contents are saved to RAM. When battery runs out, hibernate occurs.
5 - Behaves as 1 but applicable only for modern Mac that uses "Secure virtual memory".
7 - Behaves as 3 but applicable only for modern Mac that uses "Secure virtual memory".


  • For me, I am using MacBook Pro and I know that I am using "Secure virtual memory" (System Preferences -> Security), so 5 is my choice. I want my Mac to hibernate everything I sleep.
  • Make an alias in your .bash_profile under your home directory:
alias hibernateon="sudo pmset -a hibernatemode 5"
alias hibernateoff="sudo pmset -a hibernatemode 0"

  • "Source" your bash_profile file and your are done!
  • Whenever you want to hibernate your computer, if it is not set already, just go to terminal and execute hibernateon. If you want to turn it off, hibernateoff and you are all set.

Tool


It was known that if you want to avoid hassle setting up in command line, there is a dashboard widget, called Deep Sleep that will do the trick do. Somehow it does not work on my MacBook Pro.