-
Notifications
You must be signed in to change notification settings - Fork 1
/
Defer date script.applescript
155 lines (78 loc) · 3.64 KB
/
Defer date script.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
tell application "OmniFocus"
set deferTime to value of setting id "DefaultStartTime" of default document
set splitDeferTime to my splitText(deferTime as string, ":")
set deferTimeHours to first item of splitDeferTime
set deferTimeMinutes to second item of splitDeferTime
set deferTimeSeconds to third item of splitDeferTime
tell content of first document window of front document
set selectedTasks to selected trees
repeat with taskNum from 1 to count of selectedTasks
set theTask to value of item taskNum of selectedTasks
(*
set simple defer date
*)
set nextDeferDate to current date
if defer date of theTask is missing value then
(*
defer date is empty (either new task or defer date was removed manually)
*)
set nextDeferDate's hours to deferTimeHours
set nextDeferDate's minutes to deferTimeMinutes
set nextDeferDate's seconds to deferTimeSeconds
else
(*
defer date is set (keep time, reschedule date only)
*)
set deferDate to defer date of theTask
set nextDeferDate's hours to deferDate's hours
set nextDeferDate's minutes to deferDate's minutes
set nextDeferDate's seconds to deferDate's seconds
end if
repeat until nextDeferDate > (current date)
set nextDeferDate to nextDeferDate + (1 * days)
end repeat
if (defer date of theTask is missing value or defer date of theTask ² (current date)) and repetition rule of theTask is missing value then
set defer date of theTask to nextDeferDate
end if
(*
set defer date according to schedule (interval)
*)
set repRule to repetition rule of theTask
if repRule is not missing value then
set repMethod to repetition method of repRule as string
set _frequency to recurrence of repRule
set _repetition to repetition method of repRule
if repMethod is equal to "fixed repetition" then
--- condititon: "Repeat From This Item's: Completion"
set nextDeferDate to next defer date of theTask
else if repMethod is equal to "start after completion" then
--- condition: "Repeat From This Item's: Assigned Dates"
set repetition rule of theTask to {repetition method:fixed repetition, recurrence:_frequency}
set nextDeferDate to next defer date of theTask
if nextDeferDate ² (current date) then
using terms from scripting additions
set nextDeferDate's day to (current date)'s day
set nextDeferDate's month to (current date)'s month
set nextDeferDate's year to (current date)'s year
end using terms from
end if
set repetition rule of theTask to {repetition method:_repetition, recurrence:_frequency}
else if repMethod is equal to "due after completion" then
--- condition: "Schedule the Next: Due Date"
--- (just created task with no due date or defer date)
set repetition rule of theTask to {repetition method:start after completion, recurrence:_frequency}
end if
repeat until nextDeferDate > (current date)
set nextDeferDate to nextDeferDate + (1 * days)
end repeat
set defer date of theTask to nextDeferDate
end if
end repeat
end tell
end tell
on splitText(theText, theDelimiter)
set AppleScript's text item delimiters to theDelimiter
set theTextItems to every text item of theText
set AppleScript's text item delimiters to ""
return theTextItems
end splitText