Display Sleep

January 2, 2007

I usually leave my Mac on when I go to bed. This means setting the display sleep to now or the next best thing, 1 minute. The most obvious way to do it is from System Prefs, but I wanted something faster:

> sudo pmset displaysleep 1

is great, but requires root prvileges (due to some of the other things you can do with it) so it’s out for any kind of automation/scripting purpose.

Enter Apple Remote Desktop. Among other niceties, ARD includes a CLI utility called systemsetup that you can use to set various system preferences, like so:

> /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Support/systemsetup -setdisplaysleep 30

Nice. Time to wrap this into something Mac-like and give it a keyboard shortcut:

property ARDPath : "/System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Support/systemsetup"



set currSleep to do shell script ARDPath & " -getdisplaysleep"



if (currSleep) does not end with "1 minutes" then

        set newSleep to 1

else

       set newSleep to 30

end if



do shell script ARDPath & " -setdisplaysleep " & newSleep

Throw that into ~/Library/Scripts and give it a fitting shortcut in System Prefs/Keyboard & Mouse.