1

How can one disable forced sleep (sleep caused by the user - often by closing lid/pressing Sleep under the apple menu) through Terminal, preferably with a Python script, on OS X? I would like to be able to run the following or similiar...

import os
cmd = """ *?*Sleep Disable Command*?* """
def fullVolume():
     os.system(cmd)

while True:
    fullVolume()

...to accomplish said task.

I have done a fair share of research, and I couldn't find much, bar this: https://developer.apple.com/library/mac/qa/qa1340/_index.html

And this: https://code.google.com/p/macosx-nosleep-extension/ https://github.com/integralpro/nosleep/releases

I believe there may be some way to incorporate code from the NoSleep extension into this script, but I am quite unsure on how to do so. Help is much appreciated! =)

The Novice
  • 124
  • 9
  • Do you mean this? `pmset noidle` – Mark Setchell Feb 06 '15 at 09:18
  • @MarkSetchell That command only prevents "idle" sleep - I need to prevent "forced" sleep. – The Novice Feb 07 '15 at 03:03
  • I don't think it's possible. From Apple docs: "...even with I/O Kit, it is not possible to prevent forced sleep, only delay it." https://developer.apple.com/library/mac/qa/qa1340/_index.html – guya Apr 13 '15 at 06:31

1 Answers1

0
osascript -e 'tell application "System Events" to sleep'

~

str1='tell application "System Events" to sleep'
os.system("osascript -e '"+ str1+ "'")
Gank
  • 4,507
  • 4
  • 49
  • 45