Plug-In: Move Tasks to Project ![Plug-in is compatible with Apple Vision Pro 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 INPUTinputForm = new Form()// CREATE TEXT FIELDtextField = new Form.Field.String("textInput","Search",null)// CREATE MENUpopupMenu = new Form.Field.Option("menuItem","Results",[],[],null)popupMenu.allowsNull = truepopupMenu.nullOptionTitle = "0 items"// ADD THE FIELDS TO THE FORMinputForm.addField(textField)inputForm.addField(popupMenu)// PRESENT THE FORM TO THE USERcurrentValue = nullformPrompt = "Enter target project title:"formPromise = inputForm.show(formPrompt,"Continue")// VALIDATE THE USER INPUTinputForm.validate = function(formObject){textInput = formObject.values["textInput"]if(textInput !== currentValue){currentValue = textInput// remove popup menuif (inputForm.fields.length === 2){inputForm.removeField(inputForm.fields[1])}}if(inputForm.fields.length === 1){// search using provided stringif (!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 = truepopupMenu.nullOptionTitle = String(searchResults.length + " items")inputForm.addField(popupMenu)return false}if(!textInput){return false}// activate button only if a menu item is selectedif(inputForm.fields.length === 2){menuValue = formObject.values["menuItem"] ?? falsereturn (menuValue === false) ? false : true}}// PROCESSING USING THE DATA EXTRACTED FROM THE FORMformPromise.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;})();