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

Sleep displays via AppleScript System
This hint allows you to sleep the display via AppleScript and the Active Screen Corners feature of Exposť. It is based on the script in this blog entry, which allows you to move the mouse cursor to the top left corner of the screen.

First of all, you need to set the Exposť functionality (in the Active Screen Corners section) of the top left corner to Sleep Display. Having done that, the following AppleScript will sleep the display:
(*
Source for the shell script:
http://hubionmac.com/wordpress/2009/09/maus-zeiger-in-applescript-via-python-bewegen/
*)

do shell script "python -c \"import objc;bndl = objc.loadBundle('CoreGraphics', globals(), '/System/Library/Frameworks/ApplicationServices.framework');objc.loadBundleFunctions(bndl, globals(),[('CGWarpMouseCursorPosition', 'v{CGPoint=ff}')]);CGWarpMouseCursorPosition((0, 0));\""

tell application "Finder" to activate
[robg adds: I tested this in 10.6, and it worked as described. This much older hint sleeps the displays via AppleScript, but only after a one-minute delay; this one uses a couple of third-party tools and AppleScript to sleep the displays with password protection; finally, if you're just interested in quickly sleeping the displays (not necessarily via script), this hint points out that Shift-Control-Eject will do just that.]
    •    
  • Currently 2.60 / 5
  You rated: 5 / 5 (10 votes cast)
 
[9,901 views]  

Sleep displays via AppleScript | 11 comments | Create New Account
Click here to return to the 'Sleep displays via AppleScript' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Sleep displays via AppleScript
Authored by: Andrew J Freyer on Apr 20, '10 08:19:59AM

Sleeping the computer, if anyone is interested, is really easy.

tell application "Finder"
sleep
end tell

---
Easier location-based computing: with Airport Location, app for 10.6. It's an early Beta, so please report bugs!

http://airportlocation.blogspot.com
Edited on Apr 20, '10 08:21:38AM by Andrew J Freyer



[ Reply to This | # ]
Sleep displays via AppleScript
Authored by: craigsheppard on Apr 20, '10 07:05:08PM

For clarification, the above hint is to sleep the display, but let the computer remain running. I think you know that, but others might miss the subtlety :)



[ Reply to This | # ]
Sleep displays via AppleScript
Authored by: metiure on Apr 20, '10 09:32:18AM

In Exposť, you can define any Active Screen Corner to Sleep Display directly, without any Applescript code.
Or am I missing smtg?



[ Reply to This | # ]
Sleep displays via AppleScript
Authored by: jecwobble on Apr 20, '10 12:32:01PM

The Expose setting is required for this script to work, not the other way around.



[ Reply to This | # ]
Sleep displays via AppleScript
Authored by: RajNR on Apr 20, '10 09:41:24AM

I hope this works! Can't wait to get home to try it.

I currently schedule my Mac to wake up in the middle of the night to run a Carbon Copy Cloner Scheduled Task. But I don't really want the screens on...

I'm hoping I can use this script as a "preflight" task. Machine wakes up, CCC starts, the screens get shut off, the Clone is made, machine goes to sleep...



[ Reply to This | # ]
Sleep displays via AppleScript
Authored by: b00le on Apr 20, '10 09:57:05AM

Wow, that looks so much simpler than ctrl-shift-eject...



[ Reply to This | # ]
Sleep displays via AppleScript
Authored by: craigsheppard on Apr 20, '10 07:06:19PM

Sometimes you want to do something without the keyboard :)



[ Reply to This | # ]
Sleep displays via AppleScript
Authored by: craigsheppard on Apr 20, '10 07:16:18PM
One annoyance with this is having to set the sleep corner, especially to the top left. I never set this hot corner as it's so easily activated every time you aim for the Apple or "application" menus.

I also sleep my display with a script (I have a mac in my living room hooked up to a TV, which I can "sleep" - then the TV turns itself off, from my phone).

I use an app called SleepDisplay which I launch remotely over ssh from my "home automation" computer. It works a treat :)

[ Reply to This | # ]

Sleep displays via AppleScript
Authored by: paulbrainerd on Apr 24, '10 07:07:28AM

You can add a modifier key with the cursor to activate a hot corner (i.e. the top left apple corner). Just go to the expose & spaces preferences and hold down the modifier key you would like when choosing the hot corner. Made the top left corner useful for me again.



[ Reply to This | # ]
Sleep displays via AppleScript
Authored by: MacBeliever on May 01, '10 11:32:08PM

This is a short version if you have XTool.osax.
move mouse {0, 0}
tell application "Finder" to activate



[ Reply to This | # ]
Sleep displays via AppleScript
Authored by: buzzwig on Jan 19, '11 08:48:41PM

Can I use this to move the cursor to locations other than the upper left corner?



[ Reply to This | # ]