Export Canvas to New OmniFocus Task

Here’s an example of using Omni Automation to transfer data between applications. In this example, the current canvas in the OmniGraffle document is exported as a PNG graphic, and attached to a newly created task in OmniFocus.

The script uses the integrated URL support in OmniFocus to create and run a URL link for creating tasks. The following is an installable OmniGraffle solitary action, which is accessed through the Automation menu.

/*{ "type": "action", "targets": ["omnigraffle"], "author": "Otto Automator", "description": "Exports the current canvas as PNG image to a new OmniFocus action.", "identifier": "com.omni-automation.og.canvas-to-new-task", "version": "1.0", "label": "Export Canvas to New OmniFocus Task", "shortLabel": "Canvas to Task" }*/ (() => { var action = new PlugIn.Action(function(selection, sender){ // action code // selection options: canvas, document, graphics, lines, solids, view var textInputField = new Form.Field.String( "taskTitle", null, null ) var inputForm = new Form() inputForm.addField(textInputField) var formPrompt = "Enter title for new task:" var buttonTitle = "Continue" var formPromise = inputForm.show(formPrompt,buttonTitle) inputForm.validate = function(formObject){ inputText = formObject.values['taskTitle'] return ((!inputText)?false:true) } formPromise.then(formObject => { var taskTitle = formObject.values['taskTitle'] var taskName = encodeURIComponent(taskTitle) var cnvsName = selection.canvas.name var attachmentName = encodeURIComponent(cnvsName + '.png') var fileTypeID = "public.png" var wrapperPromise = document.makeFileWrapper(cnvsName, fileTypeID) wrapperPromise.then(wrapper => { var encodedData = wrapper.contents.toBase64() var urlStr = "omnifocus://localhost/add?name=" + taskName + "&attachment=" + encodedData + "&attachment-name=" + attachmentName URL.fromString(urlStr).open() }) wrapperPromise.catch(function(err){ console.error(err.message) }) }) formPromise.catch(function(err){ console.error("form cancelled", err.message) }) }); action.validate = function(selection, sender) { // validation code // selection options: canvas, document, graphics, lines, solids, view return true }; return action; })();

DISCLAIMER