Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Command to Sleep Display OSX

Tags:

macos

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.

like image 871
mikeycgto Avatar asked Aug 06 '09 14:08

mikeycgto


1 Answers

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

IOKit Documentation

like image 190
Tabitha Avatar answered Dec 09 '22 00:12

Tabitha