I'm trying to read the current kPMSetClamshellSleepState
setting from my launch daemon for macOS. I tried the following approach:
io_connect_t connection = IO_OBJECT_NULL;
io_service_t pmRootDomain = IOServiceGetMatchingService(kIOMainPortDefault,
IOServiceMatching("IOPMrootDomain"));
if(pmRootDomain)
{
kern_return_t res = IOServiceOpen(pmRootDomain, current_task(), 0, &connection);
if(res == KERN_SUCCESS)
{
uint64_t outputs[1] = { };
uint32_t num_outputs = 1;
res = IOConnectCallScalarMethod(connection,
kPMSetClamshellSleepState,
NULL,
0,
outputs,
&num_outputs);
if(res == KERN_SUCCESS)
{
//Done
}
//Close connection
IOServiceClose(connection);
}
IOObjectRelease(pmRootDomain);
}
But in this case the call to IOConnectCallScalarMethod
returns 0xE00002C2
, or -536870206
, or kIOReturnBadArgument
.
How do I read a setting? Any advice.