-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathalert.py
More file actions
executable file
·46 lines (32 loc) · 1.31 KB
/
Copy pathalert.py
File metadata and controls
executable file
·46 lines (32 loc) · 1.31 KB
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
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/python
# Just a timer for now. Will expand to include a proper alarm later on.
# AppleScript docs: http://developer.apple.com/library/mac/#documentation/AppleScript/Conceptual/AppleScriptLangGuide/introduction/ASLR_intro.html
from datetime import datetime, timedelta
import time
import os
def accept_int(q):
raw_a = raw_input(q)
acc = False
while not acc:
try:
a = int(raw_a)
acc = True
except (ValueError, NameError):
print "That is not a valid input. Please enter an integer."
raw_a = raw_input(q)
return a
def create_timer():
hours = accept_int("Hours: ")
minutes = accept_int("Minutes: ")
seconds = accept_int("Seconds: ")
event_name = raw_input("Event name: ")
alert = """
osascript -e 'tell application "Finder" to display dialog "%s" buttons "OK" default button 1 with title "PyAlert"'
""" %(event_name, )
target_time = datetime.now() + timedelta(hours=hours, minutes=minutes, seconds=seconds)
print "Timer to go off at: " + datetime.strftime(target_time, "%I:%M%p")
seconds_to_target = (target_time - datetime.now()).total_seconds()
time.sleep(seconds_to_target)
button_return = os.system(alert) # returns 0 for OK button
if __name__=="__main__":
create_timer()