Created
November 30, 2013 11:50
-
-
Save yukirii/7718067 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// displaysleep | |
// | |
// Command to Sleep Display OSX | |
// http://stackoverflow.com/questions/1239439/command-to-sleep-display-osx | |
// | |
// Compile: gcc -o displaysleep -framework CoreFoundation -framework IOKIT displaysleep.c | |
// | |
#include <CoreFoundation/CoreFoundation.h> | |
#include <IOKit/IOKitLib.h> | |
/* Returns 1 on success and 0 on failure. */ | |
int display_sleep(void) | |
{ | |
io_registry_entry_t reg = IORegistryEntryFromPath(kIOMasterPortDefault, "IOService:/IOResources/IODisplayWrangler"); | |
if (reg) { | |
IORegistryEntrySetCFProperty(reg, CFSTR("IORequestIdle"), kCFBooleanTrue); | |
IOObjectRelease(reg); | |
} else { | |
return 0; | |
} | |
return 1; | |
} | |
int main(void) | |
{ | |
if ( display_sleep() == 1 ) { | |
printf("Display sleeping...\n"); | |
} | |
else { | |
printf("Failure sleep display...\n"); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment