Last active
August 29, 2015 14:06
-
-
Save FrostyX/97697ff792e3227aa8ee to your computer and use it in GitHub Desktop.
Easy-to-use "suspend after some time" program for Windows
This file contains 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
#!/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