Plug-In: Export Contents to Drafts TaskPaper Apple Vision Pro

This plug-in creates a new note in the Drafts app with the displayed contents expressed in TaskPaper format.

of-drafts

Return to: OmniFocus Plug-In Collection

Export Contents to Drafts TaskPaper
   

/*{ "type": "action", "targets": ["omnifocus"], "author": "Otto Automator", "identifier": "com.omni-automation.of.contents-to-drafts-taskpaper", "version": "1.1", "description": "Creates a new note in the Drafts app with the displayed contents in TaskPaper format.", "label": "Export Contents to Drafts", "shortLabel": "Export to Drafts", "paletteLabel": "Export to Drafts", "image": "t.square.fill" }*/ (() => { const action = new PlugIn.Action(async function(selection, sender){ date = new Date() dc = Calendar.current.dateComponentsFromDate(date) delimiter = "-" dateSlug = dc.month + delimiter + dc.day + delimiter + dc.year + " " + dc.hour + ":" + dc.minute textInputField = new Form.Field.String( "noteTitle", null, "OmniFocus " + dateSlug ) inputForm = new Form() inputForm.addField(textInputField) inputForm.validate = function(formObject){ noteTitle = formObject.values['noteTitle'] return ((!noteTitle)?false:true) } formPrompt = "Title for new draft:" buttonTitle = "Continue" formObject = await inputForm.show(formPrompt,buttonTitle) noteTitle = formObject.values['noteTitle'] noteTitle = encodeURIComponent(noteTitle) fileTypeID = "com.omnigroup.omnifocus2.export-filetype.plain-text" baseName = "Plain Text" wrapper = await document.makeFileWrapper(baseName, fileTypeID) wrapperContent = wrapper.contents.toString() console.log(wrapperContent) encodedContent = encodeURIComponent(wrapperContent) DraftsURLStr = `drafts5://x-callback-url/create?text=${noteTitle}%0A%0A${encodedContent}` URL.fromString(DraftsURLStr).call(result => { console.log(result) //--> "790A478C-66D9-4C8D-857D-5910D058C417" var openDraftURLStr = `drafts5://x-callback-url/open?uuid=${result}` URL.fromString(openDraftURLStr).open() }, err => { new Alert("SCRIPT ERROR", err.errorMessage).show() console.error(err.errorMessage) }) }); action.validate = function(selection, sender){ return true }; return action; })();