Created
February 19, 2013 18:00
-
-
Save ytsutano/4988268 to your computer and use it in GitHub Desktop.
Turning on/off OS X displays.
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
#include <CoreFoundation/CoreFoundation.h> | |
#include <IOKit/IOKitLib.h> | |
#include <iostream> | |
void set_request_idle(bool request) | |
{ | |
io_registry_entry_t entry = IORegistryEntryFromPath(kIOMasterPortDefault, | |
"IOService:/IOResources/IODisplayWrangler"); | |
if (entry == MACH_PORT_NULL) { | |
return; | |
} | |
IORegistryEntrySetCFProperty(entry, CFSTR("IORequestIdle"), | |
request ? kCFBooleanTrue : kCFBooleanFalse); | |
IOObjectRelease(entry); | |
} | |
int main(int argc, const char **argv) | |
{ | |
const std::string &command = (argc > 1) ? argv[1] : ""; | |
if (command == "idle") { | |
set_request_idle(true); | |
} else if (command == "wake") { | |
set_request_idle(false); | |
} else { | |
std::cerr << "usage: " << argv[0] << " (idle|wake)\n"; | |
return 1; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Compile with:
To turn off:
To turn on: