Is there a command/API on OS X to put the monitor into sleep mode?
By sleep mode, I mean totally kill the output to the monitor. I know in the power settings one can configure this but that is time based.
Is there a command/API on OS X to put the monitor into sleep mode?
By sleep mode, I mean totally kill the output to the monitor. I know in the power settings one can configure this but that is time based.
This can be done with a semi-undocumented api.
#include <CoreFoundation/CoreFoundation.h>
#include <IOKit/IOKitLib.h>
/* Returns 0 on success and 1 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 1;
}
return 0;
}
GCC Flags: -framework CoreFoundation -framework IOKIT
Programmatically, or as a user?
For the latter, Control+Shift+Eject.
Tested in OS X 10.9.5, you can put the display to sleep with the following command:
$ pmset displaysleepnow
Caveat: Currently, there is a bug (small annoyance, really) in sleeping the display, in OS X 10.9.5, which I found when using a sleep display action in LaunchBar. By calling this command (action or terminal), the last pressed key is always Return, so this key seems to get "stuck" when you wake up the display. You'll probably never notice it but if using some sort of double modifier key tap to invoke LaunchBar, or another app (in my case, Double Cmd), this key combination won't work until you press Return again to "release" it, after waking the display.