It takes a village to put a laptop to sleep. Over the weekend, a comment from Adam Engst solved problems for both TidBITS Irregular and me with our recalcitrant laptops. Keith has a new 17-inch MacBook Pro that has several times nearly overheated, according to its three internal temperature sensors, because it woke up after being jostled in his laptop bag. I didn't have the heat problem, but my 15-inch aluminum PowerBook G4 has long had an incontinent latch that makes the computer liable to wake up in my bag.
Adam pointed us to the command-line application, which controls power management settings. While the Energy Saver pane of System Preferences exposes some of what you can control for system-wide battery and sleep behavior, changing a number of power management settings requires firing up Terminal.
Most notable in this situation is the lidwake argument, since setting the lidwake value to 0 prevents the laptop from waking from its slumber when it detects the latch has been opened. To accomplish this, feed the following command to pmset from the command line:
sudo pmset lidwake 0
The sudo command invokes pmset as the system superuser, which is required for changing power management settings, and using sudo in turn requires that you enter an administrative password to proceed. Waking the computer from sleep after setting lidwake to 0 requires pressing a key on the keyboard.
For me, an additional argument would also be useful: powerbutton. Setting powerbutton to 1 - its default value is 0 - turns the power button into a dedicated sleep button. Otherwise, the power button brings up a dialog listing Sleep along with Restart and Shut Down. Since I never press the button except to then click Sleep, this is a nice time saver - except that my particular PowerBook doesn't support this option. To find out which options your laptop handles, type:
pmset -g cap
The pmset command writes its changes to a preference file, so there's no additional step to make these changes persistent.