Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add a script to finish and follow up
- Loading branch information
1 parent
4d5cf6b
commit 79e19c6
Showing
1 changed file
with
102 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/*{ | ||
"type": "action", | ||
"targets": ["omnifocus"], | ||
"author": "Brian Hicks", | ||
"identifier": "zone.bytes.finish-and-follow-up", | ||
"version": "1.0", | ||
"description": "Finish a task and immediately sweep for next steps", | ||
"label": "Finish and Follow Up", | ||
"shortLabel": "Finish", | ||
"paletteLabel": "Finish", | ||
"image": "checkmark" | ||
}*/ | ||
(() => { | ||
var action = new PlugIn.Action(async (selection, sender) => { | ||
try { | ||
let originalTask = selection.tasks[0] | ||
originalTask.flagged = false; | ||
|
||
let isDoneAlert = new Alert("Is this task completely done?", originalTask.name); | ||
isDoneAlert.addOption("Yep!"); | ||
isDoneAlert.addOption("Not quite"); | ||
isDoneAlert.addOption("Whoops, never mind!"); | ||
|
||
let isDoneAnswer = await isDoneAlert.show(); | ||
|
||
if (isDoneAnswer == 0) { | ||
/////////////////////////////// | ||
// Yes, it's completely done // | ||
/////////////////////////////// | ||
let currentSibling = originalTask; | ||
|
||
while (true) { | ||
let nextThingAlert = new Alert("Is there anything that has to happen next?", currentSibling.name); | ||
nextThingAlert.addOption("Yep!"); | ||
nextThingAlert.addOption("No, we're all done"); | ||
|
||
let nextThingAnswer = await nextThingAlert.show(); | ||
if (nextThingAnswer == 1) { | ||
break; | ||
} | ||
|
||
let nextSiblingForm = new Form(); | ||
nextSiblingForm.addField(new Form.Field.String("name", "What's Next?")); | ||
await nextSiblingForm.show(`What's the next thing that needs to happen after "${currentSibling.name}"?`, "Save"); | ||
|
||
currentSibling = new Task(nextSiblingForm.values.name, currentSibling.after); | ||
currentSibling.addTags(originalTask.tags); | ||
} | ||
|
||
} else if (isDoneAnswer == 1) { | ||
///////////////////////////// | ||
// No, it's not quite done // | ||
///////////////////////////// | ||
let nextThingForm = new Form(); | ||
nextThingForm.addField(new Form.Field.String("name", "What's Next?")); | ||
await nextThingForm.show(`What's the next thing that needs to happen to finish "${originalTask.name}"?`, "Save"); | ||
|
||
let currentSibling = new Task(nextThingForm.values.name, originalTask.beginning); | ||
currentSibling.addTags(originalTask.tags); | ||
|
||
while (true) { | ||
let nextThingAlert = new Alert("Is there anything that'd have to happen after this is done?", currentSibling.name); | ||
nextThingAlert.addOption("Yep!"); | ||
nextThingAlert.addOption("No, not for now"); | ||
|
||
let nextThingAnswer = await nextThingAlert.show(); | ||
if (nextThingAnswer == 1) { | ||
break; | ||
} | ||
|
||
let nextSiblingForm = new Form(); | ||
nextSiblingForm.addField(new Form.Field.String("name", "What's Next?")); | ||
await nextSiblingForm.show(`What's the next thing that needs to happen after "${currentSibling.name}"?`, "Save"); | ||
|
||
currentSibling = new Task(nextSiblingForm.values.name, currentSibling.after); | ||
currentSibling.addTags(originalTask.tags); | ||
} | ||
|
||
} else if (isDoneAnswer == 2) { | ||
/////////////////////////////////////// | ||
// Whoops, didn't mean to click that // | ||
/////////////////////////////////////// | ||
return; | ||
|
||
} else { | ||
///////////////////////////////////////// | ||
// We forgot how many answers we added // | ||
///////////////////////////////////////// | ||
new Alert("Whoops!", `I got a value of '${isDoneAnswer}' from that alert, but I'm not sure what that means. This is a plugin bug!`) | ||
return; | ||
} | ||
} catch (err) { | ||
console.error(err); | ||
} | ||
}); | ||
|
||
action.validate = function(selection, sender){ | ||
return (selection.tasks.length === 1 && !selection.tasks[0].hasChildren) | ||
}; | ||
|
||
return action; | ||
})(); |