How do I wake from display sleep in OSX 10.7.4?

后端 未结 2 1085
Happy的楠姐
Happy的楠姐 2020-12-20 01:51

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

2条回答
  •  感情败类
    2020-12-20 02:51

    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 :)

提交回复
热议问题