mac os x instant display sleep rant

2007-10-31 17:29:51 -0700

Why is it so freaking hard to bind a keyboard shortcut to putting the displays to sleep immediately in Mac OS X? In the classic Mac OS, there was a hot key that did just this, at least on PowerBooks (I can't remember exactly what it was, and I don't think it was remappable, but it was there). Whenever I stepped away from my PowerBook or didn't anticipate needing to use it right away, I could tap those keys and the backlight would instantly shut off, saving some precious juice. Nowadays, my laptop usage patterns are a bit different and I don't tend to need to squeeze out every last minute of battery life anymore. But on the desktop machines I use regularly, which have no fewer than four displays connected to them, I want to be able to put all of those displays into power saving mode immediately. The main reason is so that my bedroom isn't lit up like a Christmas tree when I want to go to sleep, but I also prefer not to waste power needlessly and hope to maybe get a little more life out of the LCD backlights by turning them off when I'm not actually using them. Let me note here that even with a black screen, LCD backlights still generate a fair amount of light; the displays really need to be off. Another factor is that not all of the displays can be plugged into the same power strip, enabling me to turn them all off and on with a single flip of a switch (e.g. Apple Cinema Displays get their power directly from the computer they are plugged into). And anyway I prefer to have a uniform mechanism for controlling display sleep regardless of which machine I'm using and whether the energy saver settings have put the displays to sleep or I have done so explicitly. Besides, it's nice to be able to just hit a key on the keyboard to wake up the displays. I think that covers the reasons why I want this feature, and hopefully preempts some of the not so helpful suggestions I've seen other netfolk offer in response to similar pleas.

Prior to Leopard, I had a shell script that looked like this:

#!/bin/sh
  
MAGIC_NUMBER=107374183
PMSET=/usr/bin/pmset
GREP=/usr/bin/grep
AWK=/usr/bin/awk
SLEEP=/bin/sleep
    
$PMSET force -a displaysleep $MAGIC_NUMBER
$SLEEP 1
$PMSET force -a displaysleep `$PMSET -g | $GREP displaysleep | $AWK '{print $2}'`
$SLEEP 1

I was able to use a QuickSilver to bind execution of this script to a function key and I was mostly happy. It executed very quickly, and did just what I wanted it to do.

But as you can see, this script relies on a magic number—one that is undocumented and is possibly even the result of a bug. Now that I've upgraded to 10.5, this magic number no longer works; the script does nothing. Without a working magic number, the best you can do with a script like this is have the display sleep after one minute (the lowest effective pmset displaysleep argument is 1; 0 disables display sleep altogether).

Leopard introduces a new feature that allows you to bind a screen corner to "Sleep Display". So now this instant display sleep feature is explicitly supported in the operating system. Sort of. As far as I can tell, there is absolutely no way other than the hot corner to access this feature. Nothing in AppleScript, nothing in pmset, nothing in keyboard shortcuts, no menu item, no hot keys documented or otherwise, nor even a system level API that I could use to write a stupid little Cocoa app. I hope I am wrong; this omission aggravates me much more than it really ought to.

UPDATE: Malcolm Hall has come to the rescue with SleepDisplay.app. Thank you, Malc!