Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent OS X from going to sleep with Python?

Is there a way to prevent a computer running OS X from going to sleep from within a Python script?

like image 509
christianbrodbeck Avatar asked Jan 08 '13 13:01

christianbrodbeck


1 Answers

You can use the built-in caffeinate command.

subprocess.Popen('caffeinate')

This is how I use it:

import sys
import subprocess

if 'darwin' in sys.platform:
    print('Running \'caffeinate\' on MacOSX to prevent the system from sleeping')
    subprocess.Popen('caffeinate')
like image 156
guya Avatar answered Dec 04 '22 08:12

guya