Plug-In: Fetch Selected Agenda Note

DISCLAIMER: Mention of third-party websites and products is for informational purposes only and constitutes neither an endorsement nor a recommendation. OMNI-AUTOMATION.COM assumes no responsibility with regard to the selection, performance or use of information or products found at third-party websites. OMNI-AUTOMATION.COM provides this only as a convenience to our users. OMNI-AUTOMATION.COM has not tested the information found on these sites and makes no representations regarding its accuracy or reliability. There are risks inherent in the use of any information or products found on the Internet, and OMNI-AUTOMATION.COM assumes no responsibility in this regard. Please understand that a third-party site is independent from OMNI-AUTOMATION.COM and that OMNI-AUTOMATION.COM has no control over the content on that website. Please contact the vendor for additional information.

This plug-in creates a new task based upon the selected Agenda note.

A link-back to the selected Agenda item is prepended to the OmniFocus task’s note. And a link-back to the created OmniFocus task is appended to the selected Agenda item’s note. You can then use these links to easily copy and transfer content between the two elements.

(NOTE: This plug-in requires OmniFocus 4.x)

TIP: The note field for projects and tasks in OmniFocus 4 supports RTF (Rich Text Format) which is used by Agenda when the “Copy As… Note Text” option is selected. So… you can copy and paste your Agenda note into the OmniFocus note field and retain its look and formatting!

Return to: OmniFocus Plug-In Collection

Video: Fetch Selected Agenda Note
Creates a new OmniFocus task based upon the selected Agenda note.
New Task with Selected Agenda Note
  

/*{ "type": "action", "targets": ["omnifocus"], "author": "Otto Automator", "identifier": "com.omni-automation.of.fetch-selected-agenda-note", "version": "1.0", "description": "Creates a new Inbox task using the title of the selected note in Agenda. In addition link-backs to both the OmniFocus and Agenda items are placed in their respective notes.", "label": "Fetch Selected Agenda Note", "shortLabel": "Fetch Agenda Note", "paletteLabel": "Fetch Agenda Note", "image": "tray.and.arrow.down.fill" }*/ (() => { const action = new PlugIn.Action(async function(selection, sender){ // action code try { // the Agenda URL for getting the selected note urlStr = "agenda://x-callback-url/get-selected-note" // convert url string to URL object callingURL = URL.fromString(urlStr) // wrap in explicit promise to give call time to complete var callPromise = new Promise((callResolve, callReject) => { // call the URL and use the response object callingURL.call(function(responseObj){ console.log(JSON.stringify(responseObj)) AGNoteID = responseObj["note"] AGNoteTitle = responseObj["note-title"] console.log(AGNoteTitle, AGNoteID) task = new Task(AGNoteTitle) // use the returned note identifier to create link linkStr = `agenda://x-callback-url/open-note` linkStr += `?identifier=${AGNoteID}` console.log(linkStr) linkURL = URL.fromString(linkStr) // prepend the link object to the item note noteObj = task.noteText linkURL = URL.fromString(linkStr) linkObj = new Text("(Agenda Link)", noteObj.style) newLineObj = new Text("\n", noteObj.style) style = linkObj.styleForRange(linkObj.range) style.set(Style.Attribute.Link, linkURL) noteObj.insert(noteObj.start, linkObj) noteObj.insert(linkObj.range.end, newLineObj) // generate markdown link to the new task itemLink = `[(OmniFocus Link)](omnifocus:///task/${task.id.primaryKey})` // reveal the note win = document.windows[0] win.perspective = Perspective.BuiltIn.Inbox win.selectObjects([task]) node = win.content.nodeForObject(task) node.expandNote(false) dataObject = new Object() dataObject["note-id"] = AGNoteID dataObject["of-link"] = itemLink callResolve(dataObject) }, function(err){ console.error(err.errorMessage) new Alert("Problem", err.errorMessage).show() callReject(null) }) }) result = (await callPromise) if(result){ AGNoteID = result["note-id"] urlStr = "agenda://x-callback-url/append-to-note" urlStr += `?identifier=${AGNoteID}` ofLinkBack = encodeURIComponent(result["of-link"]) urlStr += `&text=%0A${ofLinkBack}` URL.fromString(urlStr).open() } } catch(err){ console.error(err.name, err.message) } }); action.validate = function(selection, sender){ // validation code return true }; return action; })();