diff --git a/Finish and Follow Up.omnijs b/Finish and Follow Up.omnijs new file mode 100644 index 0000000..8538ac4 --- /dev/null +++ b/Finish and Follow Up.omnijs @@ -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; +})();