Skip to content

Instantly share code, notes, and snippets.

@ytsutano
Created February 19, 2013 18:00
Show Gist options
  • Save ytsutano/4988268 to your computer and use it in GitHub Desktop.
Save ytsutano/4988268 to your computer and use it in GitHub Desktop.
Turning on/off OS X displays.
#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;
}
@ytsutano
Copy link
Author

Compile with:

clang++ -Wall -O3 -framework Foundation -framework IOKit osxp.cpp -o osxp

To turn off:

osxp idle

To turn on:

osxp wake

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment