Created
September 1, 2011 18:53
-
-
Save samrat/1186941 to your computer and use it in GitHub Desktop.
Suspends laptop to save power during unexpected power outages(they're quite common in Nepal)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'''Checks the state of AC adapter(online or offline) and suspends the computer if offline''' | |
#while true ; do python2.7 loadsave.py ; sleep 5m; done | |
import os | |
comm = '''dbus-send --system --print-reply --dest="org.freedesktop.UPower" \ | |
/org/freedesktop/UPower org.freedesktop.UPower.Suspend''' | |
def loadsave(): | |
os.system("acpi -a > powerinfo.txt") | |
f = open('powerinfo.txt', 'r') | |
if f.read().strip() == "Adapter 0: off-line": | |
print "Putting computer to sleep" | |
os.system(comm) #suspend if ac power is not connected | |
if __name__ == '__main__': | |
loadsave() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment