-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcaff
executable file
·36 lines (28 loc) · 1.17 KB
/
caff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env python3
# system imports
import argparse
import sys, os
################################################################################
def main():
parser = argparse.ArgumentParser(description="Call system exe caffeinate \
with appropriate args, take hours args and convert to seconds")
parser.add_argument("hours",
type = int,
help="Numbers of hours to stay awake",
action="store")
args = parser.parse_args()
callCaffeinate(args.hours)
################################################################################
def callCaffeinate(hours):
seconds = hours * 3600 # 60 mins * 60 secs to get seconds
flags = "-disu" # all the things to set to stay awake
# Mac OSX specific
# assumes caffeinate is installed on the system and is in your path
time = "date '+Starting at %H:%M'"
retval = os.system(time)
cmd = "caffeinate {} -t {}".format(flags, seconds) # -t is time in seconds
print(cmd)
retval = os.system(cmd)
################################################################################
if __name__ == '__main__':
main()