Safe Sleep on OS X

I love Sleep on OS X. Compared to Hibernate in Windows or Software Suspend in Linux, I prefer it. Not only does it take only 2-3 seconds to sleep, but it wakes in about the same amount of time. I’ve only got one problem with it though: If I pull out the battery, there goes my suspended session. I’ve got to boot and log back in (while it only takes a minute or two, it’s a pain once you’re used to 2-3 seconds). The new powerbooks include a Safe Sleep mode which dumps the RAM to disk, allowing a session to survive a power failure (such as a dead battery, or swapping out the battery) in a machine. It’s a pretty handy feature in my opinion.

Today, I stumbled across a couple sites that explain how to enable this for older machines. Andrew Escobar has a nice write up but it doesn’t work if you are using the screen-spanning hack on an iBook. Matt Johnston has the writeup that Andrew based his on, along with a few scripts that automate the process for you (along with one that allows you to use screen-spanning and Safe Sleep.

There’s two modes for Safe Sleep, you can set it up to go into Safe Sleep when the power is low, or to Safe Sleep each time you sleep the machine. I’ve played with it going into Safe Sleep each time I sleep the machine, it takes about 10-15 seconds and the sleep light doesn’t come on (you have to wake it via the power button) and it took about 30-45 seconds to return to my desktop. I’m currently draining the battery now to make sure that it works (I really want to be able to swap out the battery without a reboot since I have a spare). I’ll update on the status of that a bit later.

Update: It does work when the laptop sleeps itself. I’ve found this isn’t particularly handy though as it only does it when the battery is drained. So, once you do this once, you’ve got a drained battery and no way to charge it.

So, what I’ve done is create two scripts, one to enable Safe Sleep every time the laptop sleeps and one to enable it only when the battery is low. I run the first, wait for it to sleep and then pull the battery. Afterwards, I run the second so that it will sleep normally.

I’ve mirrored Matt’s scripts locally here, and my two scripts are here.

2 thoughts on “Safe Sleep on OS X

  1. Suspend-to-ram is awesome. The only time I reboot my laptop is on kernel panics (quite common since I use it for driver developement) and kernel upgrades.

  2. Oh, I agree, I absolutely love suspend to RAM. I’ve just wanted a suspend to disk option for a while now since my iBook doesn’t have a backup power supply to hold the contents of my RAM while I swap batteries.

Leave a Reply

Your email address will not be published. Required fields are marked *