Mac OS X Sleep Modes

There are two ways that computers sleep (a.k.a. being suspended). One way is to keep the RAM powered on, and turn the rest of the computer off (suspend to RAM). This allows the computer to wake almost instantly. The disadvantage is that if your computer loses power – say, the battery runs out – you lose your session, and your computer will boot up normally when you turn it on.

The second way is to write the contents of RAM to the hard disc, and turn the computer off completely (suspend to disc). This way you can unplug it or disconnect the battery, and you won’t lose your session. The disadvantage is, it takes longer to sleep and to wake. The more RAM you have, the longer it takes. Current MacBook Pros can have 16GB of memory, which can take a couple of minutes to write to and read from disc.

Recent versions of OS X, at least from 10.5, possibly earlier, ships with its sleep mode configured to do both of the above. This works great! You get fast wake-up times, but if your battery runs out, you don’t lose your session either. On older MacBooks/MacBook Pros this means that you can swap out the battery, and still have your session in tact.

The sleep modes are configured by the ‘hibernatemode’ directive, and you can check yours as follows:

$ pmset -g | grep hibernatemode

	hibernatemode  3

The hibernate modes are as follows:

0: Suspend to RAM. RAM remains powered on while sleeping, safe sleep is disabled, wake is instant.
1: Suspend to disc, a.k.a safe sleep. RAM contents is written to disk, computer shuts down completely. Slower to wake up.
3: RAM is powered on while sleeping, but RAM contents are also written to disk before sleeping.
5: Same as mode 1, but for using secure virtual memory.
7: Same as mode 3, but for using secure virtual memory.

Of course, mode 3 still means that your shiny MacBook is spending a fair bit of time writing to disc every time you close the lid. Even my 2008 vintage MacBook Pro can go about a month in mode 0 or 3 before the (now 5 year old) battery runs out. So for all practical purposes, suspend to disc is completely unnecessary. To set it to 0, do the following:

$ sudo pmset -a hibernatemode 0

Once you’ve set it to 0, you can free up some space by removing the RAM image:

$ sudo rm /var/vm/sleepimage

AMOD trouble

I use an AMOD AGL3080 GPS logger in my photography. For a few days now, I cannot get it to do anything. The storage light stays on, but nothing happens. I thought that I’m out of disc space, maybe the trash is taking up all the free space? But that seemed not to be the case – I had 112MB free.

Today I got to look at this more closely for the first time. In the .Trashes directory, there is a ‘501’ directory, and under that, I get the following:

$ ls -lha
ls: QžÇØ\026gYø.œ?\036: No such file or directory
ls: ýdßÞæer˜.^ín: No such file or directory
$
$ rm *
rm: cannot remove `QžÇØ\026gYø.œ?\036': No such file or directory
rm: cannot remove `ýdßÞæer˜.^ín': No such file or directory

Eventually, I gave up and plugged it into a linux box. Now the ‘501’ didn’t show up as a directory any more, but as a file. rm -rf, unmount it, switch it on, and what do you know, it’s working! I’m not sure if just deleting the 501 from the terminal in OSX would have worked, it probably would have. I just find it strange that it showed up as a directory and not a regular file.

Cisco VPN – Error 51

All weekend I have been having trouble connecting to my work’s VPN on OS X 10.5 (Leopard). My favourite VPN client, Shimo, doesn’t even want to try, and the Cisco VPN client gives me this error:

Cisco VPN - Fix for Error 51: Unable to communicate with the VPN subsystem

All it is, is the Cisco VPN service needing a restart. Open a terminal and type:

$ sudo /System/Library/StartupItems/CiscoVPN/CiscoVPN restart

Make Apple Mail display plain text

Some of us prefer our mail clients to display mails in plain text. Here’s how to set it.  Open ~/Library/Preferences/com.apple.mail.plist, click on the Root key, click “Add Item.”  Call it ‘PreferPlainText’ and set the type to boolean.  This gives you a checkbox to enable or disable it.

You can also do it via the terminal:

defaults write com.apple.mail PreferPlainText -bool TRUE

Or to disable:

defaults write com.apple.mail PreferPlainText -bool FALSE