Plug-In: Move Tasks to Project Apple Vision Pro

Move the selected tasks to the chosen project.

Return to: OmniFocus Plug-In Collection

Move Tasks to Project
   

/*{ "type": "action", "targets": ["omnifocus"], "author": "Otto Automator", "identifier": "com.omni-automation.of.move-tasks-to-project", "version": "1.1", "description": "Move the selected tasks to the chosen project.", "label": "Move Tasks to Project", "shortLabel": "Move Tasks", "paletteLabel": "Move Tasks", "image": "archivebox.fill" }*/ (() => { const action = new PlugIn.Action(function(selection, sender){ // CREATE FORM FOR GATHERING USER INPUT inputForm = new Form() // CREATE TEXT FIELD textField = new Form.Field.String( "textInput", "Search", null ) // CREATE MENU popupMenu = new Form.Field.Option( "menuItem", "Results", [], [], null ) popupMenu.allowsNull = true popupMenu.nullOptionTitle = "0 items" // ADD THE FIELDS TO THE FORM inputForm.addField(textField) inputForm.addField(popupMenu) // PRESENT THE FORM TO THE USER currentValue = null formPrompt = "Enter target project title:" formPromise = inputForm.show(formPrompt,"Continue") // VALIDATE THE USER INPUT inputForm.validate = function(formObject){ textInput = formObject.values["textInput"] if(textInput !== currentValue){ currentValue = textInput // remove popup menu if (inputForm.fields.length === 2){ inputForm.removeField(inputForm.fields[1]) } } if(inputForm.fields.length === 1){ // search using provided string if (!textInput){var searchResults = []} else { var searchResults = projectsMatching(textInput) } searchResultNames = searchResults.map(item => item.name) searchResultIDs = searchResults.map(item => item.id.primaryKey) popupMenu = new Form.Field.Option( "menuItem", "Results", searchResultIDs, searchResultNames, null ) popupMenu.allowsNull = true popupMenu.nullOptionTitle = String(searchResults.length + " items") inputForm.addField(popupMenu) return false } if(!textInput){return false} // activate button only if a menu item is selected if(inputForm.fields.length === 2){ menuValue = formObject.values["menuItem"] ?? false return (menuValue === false) ? false : true } } // PROCESSING USING THE DATA EXTRACTED FROM THE FORM formPromise.then(function(formObject){ projectID = formObject.values["menuItem"] projectObj = Project.byIdentifier(projectID) moveTasks(selection.tasks, projectObj) URL.fromString("omnifocus://task/" + projectID).open() }) }); action.validate = function(selection, sender){ return (selection.tasks.length > 0) }; return action; })();