-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMail2Reminders.applescript
49 lines (44 loc) · 1.69 KB
/
Mail2Reminders.applescript
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
47
48
49
tell application "Mail"
# check if the user selected an email. If not exit
if selection = {} then
display dialog "mail2reminders: You should select an email" buttons {"OK"}
return
end if
# get URL and subject of selected mail
set selected_mails to selection
set selected_mail to item 1 of selected_mails
set mail_URL to "message://%3c" & selected_mail's message id & "%3e"
set mail_subject to selected_mail's subject
# ask user to choose the Reminders's list
set list_names to name of every list of application "Reminders"
set selected_lists to (choose from list list_names)
if (selected_lists is false) then
return
end if
# ask user in how many hours the notification should appear
set display_string to "Reminder in how many hours? (0 for no reminder)"
set default_answer to 0
repeat
set response to display dialog display_string default answer default_answer buttons {"OK"}
try
set n_hours to (text returned of response) as number
exit repeat
on error errstr
set display_string to errstr & return & "You have to provide a number."
set default_answer to text returned of response
end try
end repeat
set in_hours to (current date) + (n_hours * hours)
# add reminder to list (with or without due date)
tell application "Reminders"
set selected_list to (item 1 of selected_lists)
tell list selected_list
if n_hours is equal to 0 then
make new reminder at the end of reminders with properties {name:mail_subject, body:mail_URL}
else
make new reminder at the end of reminders with properties {name:mail_subject, body:mail_URL, due date:in_hours}
end if
end tell
end tell
display dialog "New task in " & selected_list & ". " buttons {"OK"}
end tell