Skip to content

Instantly share code, notes, and snippets.

@FrostyX
Last active August 29, 2015 14:06
Show Gist options
  • Save FrostyX/97697ff792e3227aa8ee to your computer and use it in GitHub Desktop.
Save FrostyX/97697ff792e3227aa8ee to your computer and use it in GitHub Desktop.
Easy-to-use "suspend after some time" program for Windows
#!/usr/bin/python
import time
import subprocess
# s -- hh:mm:ss
def str_to_sec(s):
# http://stackoverflow.com/a/6402859/3285282
l = s.split(':')
return int(l[0]) * 3600 + int(l[1]) * 60 + int(l[2])
def suspend():
# http://superuser.com/a/145463
process = subprocess.Popen(['rundll32.exe', 'powrprof.dll,SetSuspendState', '0,1,0'])
packages = process.communicate()[0]
def main():
try:
str_time = raw_input("Suspend after (hh:mm) --> ")
str_time += ":00"
time.sleep(str_to_sec(str_time))
suspend()
except KeyboardInterrupt:
print ""
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment