Plug-In: Task with Tasks

Based upon a Rosemary Orchard workflow demonstrated at Learn OmniFocus, this plug-in creates a new task with the specified sub-tasks. Empty fields will be ignored.

/*{ "type": "action", "targets": ["omnifocus"], "author": "Otto Automator", "identifier": "com.omni-automation.of.task-with-tasks", "version": "1.0", "description": "This plug-in creates a new task with the specified sub-tasks. Empty fields will be ignored.", "label": "New Task with Tasks", "shortLabel": "Task with Tasks" }*/ (() => { var action = new PlugIn.Action(function(selection, sender){ // action code // selection options: tasks, projects, folders, tags, allObjects var textInputField01 = new Form.Field.String( "main-task", "Main Task", null ) var textInputField02 = new Form.Field.String( "sub-task-1", "Sub-Task", null ) var textInputField03 = new Form.Field.String( "sub-task-2", "Sub-Task", null ) var textInputField04 = new Form.Field.String( "sub-task-3", "Sub-Task", null ) var textInputField05 = new Form.Field.String( "sub-task-4", "Sub-Task", null ) var textInputField06 = new Form.Field.String( "sub-task-5", "Sub-Task", null ) var shouldBeSequentialCheckbox = new Form.Field.Checkbox( "shouldBeSequential", "Main task is sequential", false ) var inputForm = new Form() inputForm.addField(textInputField01) inputForm.addField(shouldBeSequentialCheckbox) inputForm.addField(textInputField02) inputForm.addField(textInputField03) inputForm.addField(textInputField04) inputForm.addField(textInputField05) inputForm.addField(textInputField06) var formPrompt = "Enter the title for the main task and any other sub-tasks:" var buttonTitle = "Continue" var formPromise =,buttonTitle) inputForm.validate = function(formObject){ var inputText01 = formObject.values['main-task'] var inputText01Status = (!inputText01)?false:true var validation = (inputText01Status) ? true:false return validation } formPromise.then(function(formObject){ var mainTaskTitle = formObject.values['main-task'] var subTask1Title = formObject.values['sub-task-1'] var subTask2Title = formObject.values['sub-task-2'] var subTask3Title = formObject.values['sub-task-3'] var subTask4Title = formObject.values['sub-task-4'] var subTask5Title = formObject.values['sub-task-5'] var shouldBeSequential = formObject.values['shouldBeSequential'] var task = new Task(mainTaskTitle,inbox.beginning) if(shouldBeSequential === true){task.sequential = true} if(subTask1Title){new Task(subTask1Title,task.ending)} if(subTask2Title){new Task(subTask2Title,task.ending)} if(subTask3Title){new Task(subTask3Title,task.ending)} if(subTask4Title){new Task(subTask4Title,task.ending)} if(subTask5Title){new Task(subTask5Title,task.ending)}[0].perspective = Perspective.BuiltIn.Inbox[0].selectObjects([task]) }) formPromise.catch(function(err){ console.error("form cancelled", err.message) }) }); action.validate = function(selection, sender){ // validation code // selection options: tasks, projects, folders, tags, allObjects return true }; return action; })();