13

I want to wake system from sleep programmatically, is there any way to do this?

I have read following link: http://developer.apple.com/mac/library/qa/qa2004/qa1340.html

this only talk about getting notification , but not sure is there any way to wake system from sleep?

I appreciate some thread to the information...

Update:

As per the suggestion I tried with IOPMSchedulePowerEvent

Code I have used:

NSCalendarDate  *timeIntervalSinceNow = [NSCalendarDate dateWithTimeIntervalSinceNow:40];
IOReturn result = IOPMSchedulePowerEvent ((CFDateRef)timeIntervalSinceNow, NULL, CFSTR(kIOPMAutoWake)); 

Result:

It fails in MacBook if lid closed

Am I doing some thing wrong or Any solution?

rogerdpack
  • 62,887
  • 36
  • 269
  • 388
Girish Kolari
  • 2,515
  • 2
  • 24
  • 34
  • See also https://github.com/iccir/Fermata but like others it just "prevents" sleep when in clamshell, dunno if there's anyway to "wake up" a sleeping mac... – rogerdpack Dec 15 '17 at 18:20

1 Answers1

6

You can schedule wake up events with IOPMSchedulePowerEvent through the power manager. You may be able to schedule an immediate wake up. pmset is a command line wrapper for the power manager. You can also prevent sleep with IOCancelPowerChange in certain cases.

You may be able to prevent sleep or wake up by generating a mouse or key event. One way to generate events is with CGPostKeyboardEvent.

Edit:

Normal sleep is different from clamshell closed sleep. To affect the latter you must write a kernel extension like Insomnia.

drawnonward
  • 53,459
  • 16
  • 107
  • 112
  • 2
    How could you wake up by generating an event? If the computer's asleep, your code isn't running. – JWWalker Jul 23 '10 at 06:38
  • thanks,let me give a try. you mean this will work even for lid close based sleep right? – Girish Kolari Jul 23 '10 at 07:05
  • I tried with IOPMSchedulePowerEvent to wakeup from sleep , it fails in MacBook if lid closed. – Girish Kolari Jul 23 '10 at 11:08
  • You did not mention the lid being closed in your question. You will have to write a kernel extension to prevent sleep when the lid is closed. [InsomniaX](http://semaja2.net/insomniaxinfo) does this. Once you have written such a kernel extension, you will have a better idea about waking from sleep when the clamshell is down, but I suspect you will just have to prevent sleep. – drawnonward Jul 23 '10 at 16:22
  • Actually, InsomniaX is a wrapper for the [Insomnia](http://binaervarianz.de/projekte/programmieren/meltmac/) kernel extension which has source available. – drawnonward Jul 23 '10 at 16:25