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


Click here to return to the '10.5: Sleep all displays via keyboard shortcut' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
10.5: Sleep all displays via keyboard shortcut
Authored by: mzs on Apr 14, '08 07:14:25AM
Here is an email I wrote where I got the password bit to work via a hotcorner, I don't have time to format it or anything:

> System Preferences --> Security
> Check the box requiring password to wake this computer. . .

Sadly that does not quite work. I had the "Hot Corners..." set to "Sleep
Display" and it would not ask me for password on wake-up. I have a
solution though:

First I came across this post:

http://www.cocoabuilder.com/archive/message/cocoa/2007/11/3/192200

Re: Sleep Display
FROM : Andrew Farmer
DATE : Sat Nov 03 23:22:37 2007

On 30 Oct 07, at 15:33, Andrew James wrote:
> I noticed steve added the nice feature to sleep the display via a hot
> corner, but is there a way for us devs to hook into it? I am
> currently using
> a pmset hack which i would prefer to use a cleaner method


Undocumented, use at your own risk, etc. It ends up involving more
IOKit than Cocoa, as it turns out.

#include <CoreFoundation/CoreFoundation.h>
#include <IOKit/IOKitLib.h>

int dimDisplayNow(void) {
io_registry_entry_t r = IORegistryEntryFromPath(kIOMasterPortDefault, "IOServic
e:/IOResources/IODisplayWrangler");
if(!r) return 1;
int err = IORegistryEntrySetCFProperty(r, CFSTR("IORequestIdle"), kCFBooleanTru
e);
IOObjectRelease(r);
return err;
}

Then I found this:

http://www.imalc.com/Site/SleepDisplay.html

I disassembled the x86 version and see that it does just what that post
said.

Then I needed a Screen Saver that could run arbitrary programs:

http://swannman.wordpress.com/projects/scriptsaver/

The bonus is that ScriptSaver comes with source code as well.

Now it only runs AppleScripts so I make this one-liner:

do shell script "exec /usr/local/bin/sleepdisplay"

I compiled it like so:

osacompile -o sleepdisplay.scpt sleepdisplay.applescript

You can see from the AppleSript that I copied the sleepdisplay binary from
SleepDisplay.app/Contents/MacOS and I put sleepdisplay into
/usr/local/share/osascript.

Then I made ScriptSaver my Screen Saver (by copying it into
/Library/Screen Savers) and selecting it in the "Other" list in the Screen
Saver tab of the Desktop & Screen Saver System Preferences panel. Set some
reasonable time-outs and made the Hot Corner "Start Screen Saver" and
finally the Security option mentioned in the reply worked. Phew...

[ Reply to This | # ]