Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

An AppleScript to quickly sleep the display System
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.]
    •    
  • Currently 2.33 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (3 votes cast)
 
[46,270 views]  

An AppleScript to quickly sleep the display | 24 comments | Create New Account
Click here to return to the 'An AppleScript to quickly sleep the display' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
An AppleScript to quickly sleep the display
Authored by: snyvlboi on Aug 15, '05 11:14:57AM

'DIM' is deprecated in 10.4. It is replaced by 'displaysleep.'

In addition, this 'hint' was originally posted at:

http://wincent.org/article/articleview/36/1/8/



[ Reply to This | # ]
An AppleScript to quickly sleep the display
Authored by: mattybinks on Aug 15, '05 12:10:03PM

Where did you find the pmset dim command? I've been looking for a way to script my monitor the way you did but never found a good way to set the brightness of the display.



[ Reply to This | # ]
An AppleScript to quickly sleep the display
Authored by: GlowingApple on Aug 15, '05 12:44:39PM
I prefer to use
do shell script "sleep 90"
as it doesn't steal nearly as many CPU cycles as the wait command does.

---
Jayson --When Microsoft asks you, "Where do you want to go today?" tell them "Apple."

[ Reply to This | # ]

An AppleScript to quickly sleep the display
Authored by: sjmills on Aug 15, '05 05:01:34PM
When I switched my script to use do shell script "sleep 65", the displays woke back up after the sleep 65 exited. Must be a difference in what sleep and delay do.

[ Reply to This | # ]
An AppleScript to quickly sleep the display
Authored by: garbanzito on Aug 15, '05 07:33:31PM

try this:

do shell script ("pmset dim 1; sleep 90; pmset dim 30") with administrator privileges

then just type in your password when it runs (much safer than storing your password in a script)



[ Reply to This | # ]
An AppleScript to quickly sleep the display
Authored by: garythemacguy on Aug 15, '05 03:49:20PM
My normal day-to-day account is a non-admin account. This script, as it stands, won't work - it assumes that your account is an admin account. However, it turns out, in 10.4 at least (sorry, I don't have 10.3 available to check), it's simple to modify it to work for non-admin accounts.

Simply add

  user name "string"
to each of the 'pmset' lines.

eg

do shell script ("pmset displaysleep 1") 
  user name "your_admin_account name" 
  password "your_admin_password" 
  with administrator privileges

Many thanks for this tip - I'll certainly be making use of it, both in this context and maybe in others!!

[ Reply to This | # ]

An AppleScript to quickly sleep the display
Authored by: bdog on Aug 15, '05 05:53:37PM

Yea, one big feature I miss from OS 9... Command-Brightness key (on a laptop's keyboard anyway). That would sleep the display. Too bad they didn't include it in OS X... :-(



[ Reply to This | # ]
An AppleScript to quickly sleep the display
Authored by: bdog on Aug 15, '05 05:56:36PM

Wow, just noticed something very strange! When I keep rapidly pressing Command-Brightness, it causes artifacts on the display and sometimes a block of the screen flashes slightly. This is one of the strangest things ever...!



[ Reply to This | # ]
An AppleScript to quickly sleep the display
Authored by: Jonsi on Aug 15, '05 08:15:05PM

Why not use the Sceen Saver's "Hot Corner"? A script that moves the cursor to the hot corner...



[ Reply to This | # ]
An AppleScript to quickly sleep the display
Authored by: quazywabbit on Aug 16, '05 12:11:47AM

I myself, don't like the hot corners. Now the feature is neat, but not that useful to me.



[ Reply to This | # ]
An AppleScript to quickly sleep the display
Authored by: JiBB on Aug 18, '05 02:23:49AM

That just turns on the screensaver, but doesn't actually power off the display.



[ Reply to This | # ]
An AppleScript to quickly sleep the display
Authored by: car1son on Aug 15, '05 10:10:03PM
I'm curious why

tell application "Finder" to sleep

doesn't work work for Mac in question?

[ Reply to This | # ]

An AppleScript to quickly sleep the display
Authored by: jgl24 on Aug 15, '05 11:01:27PM
I think they're trying to just put the display to sleep, and not the whole computer. I've been doing something similar from the terminal:
alias sleeper='osascript -e "tell Application \"System Events\" to sleep"'
I put this line into my ~/.profile file and then whenever I want a quick battery save I just type sleeper.

[ Reply to This | # ]
An AppleScript to quickly sleep the display
Authored by: bdog on Aug 15, '05 11:02:45PM

This puts the entire system to sleep. The goal of this hint is to only sleep the display.



[ Reply to This | # ]
An improved shell script.
Authored by: JiBB on Aug 18, '05 02:59:09AM
I found that the following shell script works, and it improves upon the original hint in two ways. It does not need to be run as root (or with admin privileges) because it uses the -force option of pmset to only effect the settings in memory. It also checks which set of settings should be used (Battery or AC charger) and reading and then restoring the original sleep time for that set of settings. E.g, if I have my display set to sleep after 5 minutes while on battery power and after 15 minutes while on AC power, this script will still restore these settings when done, unlike the original.

#! /bin/sh

# instasleep.sh
# Aug. 18, 2005, by JiBBerish@gmail.com
#
# Sets the display to sleep after one minute, then restores settings
# ..once sleep (presumeably) has begun.  Uses the force option, so
# ..doesn't need to be run as root.

orig_displaysleep=`pmset -g | grep displaysleep | awk '{print $2}'`
mode=`pmset -g | grep '\*$' | sed -e '/^AC/c\\
c' -e '/^Batt/c\\
b'`
echo "To restore orig. settings: pmset -mode displaysleep $orig_displaysleep"
echo "Sleeping in just a minute..."
pmset force -$mode displaysleep 1
sleep 70
pmset force -$mode displaysleep $orig_displaysleep
echo "Settings restored"


[ Reply to This | # ]
An improved shell script.
Authored by: JiBB on Aug 20, '05 02:22:10AM
Whoops, the line
echo "To restore orig. settings: pmset -mode displaysleep $orig_displaysleep"
should be
echo "To restore orig. settings: pmset -$mode displaysleep $orig_displaysleep"


[ Reply to This | # ]
An AppleScript to quickly sleep the display
Authored by: pbonsall on Aug 18, '05 03:46:47AM

Using Option-Command-Eject (but not Option-Command-Power) sends my iBook to sleep. (From Mac Help, Mac OS X keyboard shortcuts)



[ Reply to This | # ]
An AppleScript to quickly sleep the display
Authored by: pbonsall on Aug 18, '05 03:49:56AM

Ooops! I get it: send *display* to sleep. Sorry!



[ Reply to This | # ]
An AppleScript to quickly sleep the display
Authored by: Nonsanity on Sep 22, '05 04:39:28PM

Combining this hint with the screensaver "ScriptSaver" (on VersionTracker) is great for laptops. Instead of draining the battery with a screen saver or waiting for a "working" delay period to end for Energy Saver to kick in... Starting the screen saver manually with the sleep corner also now puts the dispaly to sleep after a minute.

Exactly what I was looking for!



[ Reply to This | # ]
An AppleScript to quickly sleep the display
Authored by: myfriendscallmep on Apr 05, '07 06:00:50AM
Here's both a dashboard widget and a small application that will do the trick:
http://linestreet.googlepages.com/

No waiting a minute anymore....

[ Reply to This | # ]
An AppleScript to quickly sleep the display
Authored by: alset on Apr 21, '07 07:47:04PM

It appears that the author of the above listed app used a combination of the hint from JiBB (see above) and original code. It seems pmset will force the display to sleep instantly if the number of minutes specified before sleep is 107374183. This is combined with JiBBs method of forcing sleep and collecting / setting the original Energy Saver setting for display sleep.

An example can be seen by searching for 'pmset 107374183' with Google.

---
standing on the shoulders of giants



[ Reply to This | # ]
A sleep display application for Leopard
Authored by: zebrum on Nov 13, '07 10:58:48PM
On Leopard you can use this.
http://www.macupdate.com/info.php/id/26234/sleep-display
Its does the same as what the hot corner sleep function can do but its in application form.

[ Reply to This | # ]
An AppleScript to quickly sleep the display
Authored by: Nago on May 21, '10 01:21:57AM

Control+Shift+Eject

Quick, handy and it asks for your password (wether that is an advantage/disadvantage depends on you)



[ Reply to This | # ]
An AppleScript to quickly sleep the display
Authored by: nooby on Dec 05, '10 05:35:37AM

I found a simple solution ,
just set the brightness to be very low, so you get the same effect of display sleeping.
a script can be used to switch between normal and low brightness. like below

tell application "System Preferences" to set current pane to pane "com.apple.preference.displays"
tell application "System Events"
tell slider 1 of group 2 of tab group 1 of window 1 of process "System Preferences"
if value > 2.0E-4 then
set value to 1.0E-4
else
set value to 1.0E-3
end if
end tell
set visible of process "System Preferences" to false --to hide the window into background
end tell

hope that helps someone
note you can only get back from this kind of "sleeping" via the script or the brightness key :)



[ Reply to This | # ]