add a script to finish and follow up

picker-v2
Brian Hicks 2022-08-30 17:15:21 -05:00
parent 4d5cf6b7ce
commit 79e19c6efc
Signed by: brian
GPG Key ID: C4F324B9CAAB0D50
1 changed files with 102 additions and 0 deletions

102
Finish and Follow Up.omnijs Normal file
View File

@ -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;
})();