Thursday, June 30, 2011

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

Source code copied from the file SleepDisplay.zip found here:
http://forums.macrumors.com/showthread.php?p=8864913#post8864913
link to file here:
http://goo.gl/3C1ww

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



First:
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);
  IOObjectRelease(r);
 }
 return 0;
}
===========

Second:
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

Third:
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.

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

Fifth:
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