-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeferThisInstance.omnifocusjs
40 lines (33 loc) · 1.31 KB
/
deferThisInstance.omnifocusjs
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
/* global PlugIn duplicateTasks */
/*{
"type": "action",
"targets": ["omnifocus"],
"author": "Kaitlin Salzke",
"identifier": "com.KaitlinSalzke.DeferThisInstance",
"version": "1.2",
"description": "Duplicates a repeating task to modify its defer date without affecting future instances",
"label": "Defer This Instance",
"shortLabel": "Defer This Instance",
"image": "arrow.forward.square.fill"
}*/
(() => {
const action = new PlugIn.Action(async (selection, sender) => {
const oTask = selection.tasks[0] || selection.projects[0].task
// prompt for new defer date
const form = new Form()
form.addField(new Form.Field.Date('deferDate', 'New Defer Date', null, null))
await form.show('Defer Until...', 'OK')
// make a non-repeating copy of the task
const nTask = oTask.project === null ? duplicateTasks([oTask], oTask.before)[0] : duplicateSections([oTask.project], oTask.project.before)[0].task
nTask.repetitionRule = null
nTask.deferDate = form.values.deferDate
// skip the original task
oTask.drop(false)
})
action.validate = (selection, sender) => {
// available if a single repeating task is selected
const selected = [...selection.tasks, ...selection.projects.map(p => p.task)]
return selected.length === 1 && selected[0].repetitionRule !== null
}
return action
})()