Sleep displays via AppleScript

Apr 20, '10 07:30:00AM

Contributed by: Lutzifer

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.]

Comments (11)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20100418152304108