Plug-In: Replace Note Text with Clipboard

This plug-in will replace the text content of the note of the selected project or task with the text content of the clipboard.

Return to: OmniFocus Plug-In Collection

Replace Note Text with Clipboard
  

/*{ "type": "action", "targets": ["omnifocus"], "author": "Otto Automator", "identifier": "com.omni-automation.of.replace-note-text-with-clipboard", "version": "1.2", "description": "Will replace the text content of the note of the selected project or task with the text content of the clipboard.", "label": "Replace Note Text with Clipboard", "shortLabel": "Replace Note Text", "paletteLabel": "Replace Note Text", "image": "arrow.right.doc.on.clipboard" }*/ (() => { const action = new PlugIn.Action(function(selection, sender){ try { if (selection.tasks.length === 1){ var item = selection.tasks[0] } else if(selection.projects.length === 1){ var item = selection.projects[0] } else { throw {"name":"Selection Error", "message":"Please select a single project or task."} } var alertTitle = "CONFIRMATION" var alertMessage = "Replace note text with text from the clipboard?" var alert = new Alert(alertTitle, alertMessage) alert.addOption("Replace") alert.addOption("Cancel") alert.show(buttonIndex => { if (buttonIndex === 0){ if(app.userVersion.atLeast(new Version("4"))){ // show note tree = document.windows[0].content node = tree.nodeForObject(item) node.expandNote(true) } // replace text console.log(item) item.note = Pasteboard.general.string } }) } catch(err){ new Alert(err.name, err.message).show() } }); action.validate = function(selection, sender){ return ( Pasteboard.general.hasStrings && selection.databaseObjects.length === 1 ) }; return action; })();