-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathAppend Note to Most recently updated task.applescript
99 lines (79 loc) · 2.69 KB
/
Append Note to Most recently updated task.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
(*
# DESCRIPTION #
Appends a note to the most recently modified task in OmniFocus.
- By default, the clipboard contents are used for the note
- If triggered from LaunchBar or Alfred, you can use different text
See https://github.com/dbyler/omnifocus-scripts for updates
# LICENSE #
Copyright © 2015-2020 Dan Byler (contact: [email protected])
Licensed under MIT License (http://www.opensource.org/licenses/mit-license.php)
(TL;DR: no warranty, do whatever you want with it.)
# CHANGE HISTORY #
2020-02-16
- Update notification message; finish purging Growl code
2019-07-16
- First release (based on Append note to Newest Task)
Note to self: see comment on line 82. This may be brittle and require a different fix
*)
-- To change settings, modify the following properties
property showSummaryNotification : true --if true, will display success notifications
on main(q)
if q is missing value then
set q to (the clipboard)
end if
tell application "OmniFocus"
tell front document
set myTask to my getLastModifiedTask()
if myTask is false then
display notification "No recent items available" with title "Error"
return
end if
tell myTask
insert q & "
" at before first paragraph of note
end tell
if showSummaryNotification then
set alertTitle to "Note added to " & name of myTask
set alertText to "\"" & q & "\""
display notification alertText with title alertTitle
end if
end tell
end tell
end main
on getLastModifiedTask()
tell application "OmniFocus"
tell front document
set allTasks to {}
set maxAge to 8
repeat while length of allTasks is 0 and maxAge ≤ 524288
set maxAge to maxAge * 2
set earliestTime to (current date) - maxAge * 60
set allTasks to (every flattened task whose (modification date is greater than earliestTime ¬
and repetition is missing value))
end repeat
if length of allTasks > 0 then
set lastTask to first item of allTasks
set lastTaskDate to modification date of lastTask
repeat with i from 1 to length of allTasks
if modification date of (item i of allTasks) ≥ lastTaskDate then --a task's root task, if present, will have the same modification date as the task, but seems to appear first in the list, so this should pull the task
set lastTask to (item i of allTasks)
set lastTaskDate to modification date of lastTask
end if
end repeat
return lastTask
else
return false
end if
end tell
end tell
end getLastModifiedTask
on notify(alertName, alertTitle, alertText)
display notification alertText with title alertTitle
end notify
main(missing value)
on alfred_script(q)
main(q)
end alfred_script
on handle_string(q)
main(q)
end handle_string