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": "Nyhthawk Productions", "description": "Exports the current canvas as PNG image to a new OmniFocus action.", "label": "Add PNG to New OmniFocus Task", "paletteLabel": "Add PNG to OmniFocus" }*/ var _ = function(){ var action = new PlugIn.Action(function(selection, sender) { // action code // selection options: canvas, document, graphics, lines, solids, view taskName = encodeURIComponent(document.name) cnvsName = document.windows[0].selection.canvas.name attachmentName = encodeURIComponent(cnvsName + '.png') wrapper = document.fileWrapper('public.png') encodedData = wrapper.contents.toBase64() urlStr = "omnifocus://localhost/add?name=" + taskName + "&attachment=" + encodedData + "&attachment-name=" + attachmentName URL.fromString(urlStr).call(function(result){}) }); action.validate = function(selection, sender) { // validation code // selection options: canvas, document, graphics, lines, solids, view return true }; return action; }(); _;

 15  The name for the new task will be the document name. Encode it for use in the OmniFocus URL.

 16  Get the name of the current canvas.

 17  The name of the attached PNG file will be the canvas name appended with the file extension. Encode for use with the OmniFocus URL.

 18  Create a new file wrapper for PNG export.

 19  Extract the file wrapper data (PNG) and encode it using base64 encoding for inclusion in the OmniFocus URL.

 20  Create the URL string of the OmniFocus URL for creating a new task with an attachment.

 21  Turn the URL string into a URL object and execute using the call() method.


This webpage is in the process of being developed. Any content may change and may not be accurate or complete at this time.