Thursday, June 30, 2011

sleep display instantly hack (not mine, found via googles)

Source code copied from the file found here:
link to file here:

you can just download this file above and extract SleepDisplay into your Applications folder and be done, but I wanted to see the source and then compile it myself, so I did the steps below...

save the following (between the lines) as a text file, use "SleepDisplay.rtf"
// gcc -Wall SleepDisplay.c -o SleepDisplay -framework CoreFoundation -framework IOKit
#include <CoreFoundation/CoreFoundation.h>
#include <IOKit/pwr_mgt/IOPMLib.h>
int main (int argc, const char * argv[])
 io_registry_entry_t r = IORegistryEntryFromPath(kIOMasterPortDefault, "IOService:/IOResources/IODisplayWrangler");
 if (r) {
  IORegistryEntrySetCFProperty(r, CFSTR("IORequestIdle"), kCFBooleanTrue);
 return 0;

change the extention .rtf to .c so now the file name is "SleepDisplay.c" to do this I ran in terminal:
mv SleepDisplay.rtf SleepDisplay.c

run terminal in the same folder as the file and copy the next line into it & hit return:
gcc -Wall SleepDisplay.c -o SleepDisplay -framework CoreFoundation -framework IOKit
if it doesn't work you might have to use "su" first and type in your admin password then run the command again.

double click the new file "SleepDisplay" to make the displays turn off instantly

put the file "SleepDisplay" in "/Applications" folder and call it with scripts or command line for automation.

1 comment:

Mark Brown said...

If you have XCode installed, you're going to automatically open .c file

Post a Comment