You’re cheap or cannot afford a business class, cross-Atlantic flight yet?
Well, this means no charger access for your beloved portable Mac along the journey (roughly 13 hours from San Francisco to London).
Anyway, you can still be wise while being cheap or frugal. You’re a wise and classy traveling geek, who carries a backup battery.
Now imagine you’re in the middle of a very hot debugging session, with numerous apps running spanning across all your Spaces and battery meter just turned red.
You have a backup battery but how can you change it without losing your current state?
Your alternatives are
to let the battery drain and OS X to go into sleep. Wait for some couple of hours to a safe sleep (which in fact is hibernation) and replace your battery.
or force a safe sleep immediately. Change the battery and continue from where you left.
Obviously, the first alternative is not something you were looking for.
-
Launch Terminal and give the command
sudo pmset hibernatemode 1 Press the power button or click Apple in the menu bar and select Sleep. It can take some time depending on your memory size (main memory + graphics card memory to be exact) to dump all of it to disk. Wait until fans stop and white led in front starts to blink.
Now you can replace your battery safely.
Press the power button. OS X will restore the memory from the sleep image on the disk. …And there you go. The exact state before sleep.
-
Now you need to go back to fast sleep & wake settings. You don’t want your Mac to hibernate every time lid is closed or idle timeout requests a sleep.
sudo pmset hibernatemode 3sudo rm /var/vm/sleepimage
That’s it.
P.S.: If you have a unibody, non-removable battery MacBook Pro, obviously you can’t replace battery that easy but it’s worth giving a try at 30.000 feet.
P.P.S.: In case you’re interested with the technical details of this solution, pmset(1) man page is what you’re looking for.