How do I wake from display sleep in OSX 10.7.4?
Asked Answered
S

2

2

In the most recent version of OSX Lion, how do you wake up the machine from display sleep? This is in response to network activity.

In 10.7.3 this was possible with the following call:

IOPMAssertionID id = 0;
IOPMAssertionCreateWithName(kIOPMAssertionTypeNoDisplaySleep,
                            kIOPMAssertionLevelOn, reason, &id)

However, this does not work in 10.7.4. What can be done instead?

Saprogenic answered 15/5, 2012 at 10:29 Comment(0)
D
1

I have not yet tested the performance implications nor the interaction with the idle timer itself, but:

io_registry_entry_t regEntry = IORegistryEntryFromPath(kIOMasterPortDefault, "IOService:/IOResources/IODisplayWrangler");
if (regEntry != MACH_PORT_NULL) {
        IORegistryEntrySetCFProperty(regEntry, CFSTR("IORequestIdle"), kCFBooleanFalse);
        IOObjectRelease(regEntry);
}

works in 10.7.4 to wake the screen from idle.

Dissuasive answered 28/5, 2012 at 19:36 Comment(1)
Note also that a cocoa-dev contributor says that this will cause a kernel panic on PPC machines.Dissuasive
P
0

It appears from the docs that the way to "wake up" the display these days is:

IOPMAssertionID assertionID2;
IOPMAssertionDeclareUserActivity(CFSTR("Your reasoning"),
       kIOPMUserActiveLocal, &assertionID2);

The IOPMAssertionCreateWithName(...) way from original the question only "prevents display going to sleep" if it's already on (though it does work and can also be used to prevent it from going to sleep for a duration of time).

The way the docs method for "keeping" the display on works about the same way as IOPMAssertionCreateWithName

IOPMAssertionID m_disableDisplaySleepAssertion;    
IOReturn success2 = IOPMAssertionCreateWithDescription(
  kIOPMAssertionTypePreventUserIdleDisplaySleep, reasonForActivity, NULL, NULL, NULL, 0, NULL, &m_disableDisplaySleepAssertion); 
if (success2 == kIOReturnSuccess) {
    // screen will stay on, do you work
    success = IOPMAssertionRelease(m_disableDisplaySleepAssertion);
}

If you want to "turn it on and keep it on forever" then IOPMAssertionDeclareUserActivity followed by the above, or just call IOPMAssertionDeclareUserActivity over and over again somehow.

You could also call out to the caffeinate built-in command line utility I suppose :)

Parameter answered 15/12, 2017 at 18:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.