views:

108

answers:

2
+1  A: 

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
How could you wake up by generating an event? If the computer's asleep, your code isn't running.
JWWalker
thanks,let me give a try. you mean this will work even for lid close based sleep right?
Girish Kolari
I tried with IOPMSchedulePowerEvent to wakeup from sleep , it fails in MacBook if lid closed.
Girish Kolari
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
Actually, InsomniaX is a wrapper for the [Insomnia](http://binaervarianz.de/projekte/programmieren/meltmac/) kernel extension which has source available.
drawnonward
+1  A: 

It looks like IOPMSchedulePowerEvent is what you want.

Edit: Dang, somebody answered before I could, and now I don't seem to be able to delete my answer.

JWWalker