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

Toggle display sleep time with one keypress System
Like quite a few Mac users, my iMac lives right beside my bed, and though this is great, I like turning the display off when I go to sleep. For the longest time, every night I would go to System Preferences -> Energy Saver and slide the time down to 1 minute, and then back to 45 minutes in the morning. Although I've seen this hint, which does the changing for you, for the occasional time when I would sleep my display then realize I wanted to check something, I'd have to run the script again (or worse, wait 90 seconds, then run it).

Finally, however, I've come up with a simple solution using Butler and GeekTool: one keystroke to toggle between my two settings, and an unobtrusive 45 or 1 in the bottom corner of the screen.

First off, in Butler add a new AppleScript smart item, and paste this in as the source:
set thetime to 
  (do shell script 
  "pmset -g | grep displaysleep | awk '{ print $2; }'") 
  as number
if thetime is 1 then
  set thetime to 45
else
  set thetime to 1
end if
do shell script ("pmset dim " & thetime) password 
  "YOURPASSWORDHERE" with administrator privileges
Replace YOURPASSWORDHERE with either your admin password, or for the more security-aware, just remove the password "YOURPASSWORDHERE" part, and it will prompt you each time. Next, set a keyboard trigger for the AppleScript. I'm using F16, because it's right next to the dim/brighten buttons.

Now, on to the GeekTool display! In GeekTool, add a new Shell entry, setting the refresh rate to every five seconds (more or less depending on how responsive you want it to be), and paste this in as the command:
pmset -g | grep displaysleep | awk '{ print $2; }'
Position it to your liking and choose a font (I did white/Arial). That's it! Toggling your screen's display time is just a keyboard stroke away!
    •    
  • Currently 2.60 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (5 votes cast)
 
[28,589 views]  

Toggle display sleep time with one keypress | 20 comments | Create New Account
Click here to return to the 'Toggle display sleep time with one keypress' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Toggle display sleep time with one keypress
Authored by: mshmgi on Jul 28, '06 08:46:28AM

You could also set up a "hot corner" (System Preferences >> Desktop & Screen Saver >> Hot Corners) that starts a blank screen saver.

Whenever I drag my cursor to the lower left hand corner, my screen goes black and stays that way until I return. No need to install 2 additional pieces of software.



[ Reply to This | # ]
Toggle display sleep time with one keypress
Authored by: filmsmith on Jul 28, '06 09:42:58AM

The problem with that (at least on my Dual Core iMac) is that the screen doesn't actually turn off. There's a faint glow because the screen is still on, but not showing any color. Still quite annoying when trying to get some sleep.



[ Reply to This | # ]
Toggle display sleep time with one keypress
Authored by: LeeH on Jul 28, '06 09:12:55AM

Depending on your machine, a simpler way might be:

1) go to Energy Saver pref panel
2) Click on options
3) Be sure "All power button to sleep the computer" is checked
4) Close System preferences

Now, simply press the power button for a second and let go. The computer goes to sleep. Enjoy a good night's rest. :-)



[ Reply to This | # ]
Toggle display sleep time with one keypress
Authored by: filmsmith on Jul 28, '06 09:45:17AM

The problem with THIS solution is that it sleeps the computer whereas the intent of the hint was to sleep just the display. If you've got a large rendering for a movie going on or a timely upload, leaving the computer awake all night is clearly the more viable option.

Obviously, the same applies to the keyboard hotkey to sleep the computer.



[ Reply to This | # ]
Toggle display sleep time with one keypress
Authored by: johnsawyercjs on Dec 23, '07 03:13:00AM

There are also some Macs that won't go to sleep, or won't stay asleep, so telling them to sleep is ineffective, whereas telling the display to sleep usually is.



[ Reply to This | # ]
Toggle display sleep time with one keypress
Authored by: jetcowbob on Jul 28, '06 09:34:44AM

Apples hints also recently put a hint out that says you can hold the command-option-eject keys for about 2 seconds and you get sleep. This is built in. No extra futzing around.



[ Reply to This | # ]
Toggle display sleep time with one keypress
Authored by: morespace54 on Dec 09, '08 06:55:02AM

Thats what I've been using for a while... Even on Tiger!

Also, for a laptop, combine this shortcut with the "Require password to wake up this computer from sleep or screen saver"" option (in Security pref pane) and I'm a A Happy Camper!



[ Reply to This | # ]
Toggle display sleep time with one keypress
Authored by: horhey23 on Jul 28, '06 11:32:32AM
I think I will be the first post not to suggest putting your whole computer to sleep in the myriad of ways OS X allows. He's talking about display sleep only - and not a screen saver either.

I was looking for the same thing as the originator of the hint and found some freeware called NightyNight [http://mildmanneredindustries.com/products.html] which I haven't actually tried, but thought I would pass along.

[ Reply to This | # ]
Toggle display sleep time with one keypress
Authored by: ob1cannoli on Jul 28, '06 01:26:42PM

thanks for this, however NightyNight just seems like an applescript application that's doing the same thing (toggling between 1 minute and 0.)



[ Reply to This | # ]
Toggle display sleep time with one keypress
Authored by: NewPerfection on Jul 28, '06 06:09:18PM

With a blank screen saver the screen is still on, just all the pixels are black. With this hint it actually shuts off the display completely while leaving the computer running. If you want the computer to sleep then just do that, but that was not the intent of this hint.



[ Reply to This | # ]
No admin version...
Authored by: jriskin on Jul 29, '06 01:00:48AM
This is about POWERSAVE on displays NOT screensavers NOR system sleep. I do a very similar script but without needing all that administrator stuff. I suppose you could combine the two methods and get both the fixed toggle and no-admin password.

So instead of
do shell script ("pmset dim " & thetime) password 
Make it...

do shell script ("pmset force dim " & thetime)
Force doesn't effect the preferences, just the settings in memory, so it doesn't require privlidges.

Too bad it still takes a full minute to take effect. I have 2 20" dell monitors and they use about 40 watts each and seem to put off most of that in heat. So it would be very helpful to have a single keypress to go in to powersave mode.

[ Reply to This | # ]
Ok, this will work better...
Authored by: jriskin on Jul 29, '06 02:25:08AM
Only one problem...since I don't set the variable, it'll never toggle...so I just spent a few minutes learning some applescript...so if this is all bad form, forgive me. I also didn't want to muck around with other apps like butler or geektool, so i just had it read the current setting aloud.

set thePath to (path to home folder) & ".monitorsleep" as string

try
	set thetime to (read file thePath as integer)
on error
	set fRef to (open for access file thePath with write permission)
	set thetime to 10
	write thetime as integer to fRef
	close access fRef
end try

set thetime to (read file thePath as integer)

if thetime is 1 then
	set thetime to 10
	say "Ten"
else
	set thetime to 1
	say "One"
end if
set fRef to (open for access file thePath with write permission)
write thetime as integer to fRef
close access fRef

do shell script ("pmset force dim " & thetime)
Hope it works out. If someone figures out how to set it to 1 second THAT would rock =)

[ Reply to This | # ]
Ok, this will work better...
Authored by: ob1cannoli on Jul 29, '06 08:29:11AM

thanks for that! I personally don't mind the password but I figure there are users that would.
and yes, the end-all-be-all of solutions would be an on/off key without any waits at all, but for now this is the best i've found.



[ Reply to This | # ]
All About the Beep
Authored by: mbordas on Jul 31, '06 07:01:32AM
I had the same problem, and I was looking to play around with Cocoa, so I wrote this little program:

http://stout.hampshire.edu/~miab03/AllAbouttheBeep.zip

It has an iTunes sleep timer that will set the display sleep to 1 minute as soon as it's started. Then you sleep all night, and when you wake up in the morning and start moving the mouse it will recognized the change in idle time and put the display sleep setting back to whatever it used to be.

This is probably less helpful then the other already mentioned alternatives if you don't like to listen to music while you fall asleep.



[ Reply to This | # ]
Authentication question
Authored by: jpkelly on Sep 09, '06 12:45:14PM

This used to work fine but now ever since I did an archive and install (to fix a Spotlight issue)
whenever I run the smart item I get a authentication dialog box saying "Butler requires that you type your password"
If I quit Butler and relaunch by double clicking it the smart item works fine. (no dialog box)
If I launch Butler via Quicksilver or when it gets launched by Login Items I get the dialog button whenever I run the Smart Item.
Any ideas?



[ Reply to This | # ]
Toggle display sleep time with one keypress
Authored by: applesjgtl on Apr 03, '07 11:11:48PM
I currently use a slightly modified form of this hint. I downloaded NightyNight from "http://mildmanneredindustries.com/products.html"; and use it along with GeekTool and the shell script mentioned in the macosx hints post. The problem with this is the fact that I have to go to my desktop in order to see the changed time. I use Growl "http://growl.info/"; and would like to use its notification system to highlight the changed time. Can anybody write a Growl script or app and post it here or email it to "emailappleaholic@gmail.com"?

[ Reply to This | # ]
Toggle display sleep time with one keypress
Authored by: myfriendscallmep on Apr 05, '07 07:15:05AM
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 | # ]
Toggle display sleep time with one keypress
Authored by: johnsawyercjs on Dec 23, '07 03:18:49AM

Nice, but doesn't work with Leopard.



[ Reply to This | # ]
Make the display sleep immediately
Authored by: arifsaha on Dec 09, '08 06:06:44AM
Here is a trick to make the display sleep immediately (no need to toggle anything): http://forums.macosxhints.com/showthread.php?p=507337#post507337

---
- http://www.arifsaha.com/


[ Reply to This | # ]

Toggle display sleep time with one keypress
Authored by: chadvonnau on Apr 11, '10 09:25:58PM

Just found out that CTRL + SHIFT + EJECT sleeps the display immediately. Thanks to ant1ers on the forum http://forums.macosxhints.com/showthread.php?p=466743#post466743



[ Reply to This | # ]