An AppleScript to quickly sleep the display

Aug 15, '05 09:50:00AM

Contributed by: vmardian

After learning that there was no possible way to force my display to sleep when I wanted it to, I thought of the following work around. Copy the following AppleScript into Script Editor (change your_password to your admin user's password) and save it as an Application:

do shell script ("pmset dim 1") password "your_password" 
 with administrator privileges
delay 90
do shell script ("pmset dim 30") password "your_password" 
 with administrator privileges
This script will change your display sleep time to 1 minute, wait 90 seconds (during which time, if you've left your computer, the display should sleep), then change it back to 30 minutes. Since it's saved as an application, you can just double-click it to run it. I use this just before going to bed.

[robg adds: A potentially interesting aside. I first test-ran this directly in Script Editor. When I did so, this simple script put an amazing load on my CPUs during the wait 90 portion of the code -- over 95% on both CPUs, in fact. Thankfully, when saved as an application, there's no such increase (only a small uptick while in the delay). As far as the testing, the script worked as expected.]

Comments (24)

Mac OS X Hints