New Draft with Text from Graphic
OmniGraffle → Drafts
OmniGraffle → 1Writer
Synopsis: Create a new Drafts document containing text copied from the selected OmniGraffle graphic (solid).

An Omni Automation action for OmniGraffle. Tap the “Install PlugIn” button to add to the OmniGraffle Automation menu on your device.

/*{ "type": "action", "targets": ["omnigraffle"], "author": "Otto Automator", "description": "This action will create a new document in the Drafts app using the text from the selected graphic.", "label": "Drafts • New Draft with Graphic Text", "shortLabel": "Drafts Doc" }*/ var _ = function(){ var action = new PlugIn.Action(function(selection, sender){ // action code // selection options: canvas, document, graphics, lines, solids, view graphic = selection.solids[0] encodedStr = encodeURIComponent(graphic.text) urlStr = "drafts5://x-callback-url/create?text=" + encodedStr url = URL.fromString(urlStr) url.call(function(result){console.log(result)}) }); action.validate = function(selection, sender){ // validation code // selection options: canvas, document, graphics, lines, solids, view if(selection.solids.length === 1 && selection.solids[0].text != ''){ return true } else { return false } }; return action; }(); _;
graphic = document.windows[0].selection.solids[0] encodedStr = encodeURIComponent(graphic.text) urlStr = "drafts5://x-callback-url/create?text=" + encodedStr url = URL.fromString(urlStr) url.call(function(result){console.log(result)})

 01-08  The action metadata. Edit the author and label tags to suit your purposes.

 20-28  The action validation routine determines the document conditions under which the action becomes available in the Automation menu. In this case, if a single solid containing text is selected.

 10-18  The action code that gets executed when the action is triggered.

 13  Store a reference to the selected graphic in the variable: graphic

 14  Use the standard JavaScript method encodeURIComponent() to percent encode the graphic’s text and store the result in the variable: encodedStr

 15  Use the Drafts URL API to create a URL for calling the Drafts app to make a new document using the encoded text appended to the URL.

 16  Convert the URL string into an instance of the URL object class.

 17  Use the call() method to execute the URL object.

The following video shows the Omni Automation action in use:

1Writer app

Because similarities in the URL Scheme support of Drafts and 1Writer, especially with the use of the create command and text parameters, the previous example action can be easily adapted to work with the 1Writer app as well, by changing the URL protocol from drafts5:// to onewriter:// while keeping the other details the same:

/*{ "type": "action", "targets": ["omnigraffle"], "author": "Otto Automator", "description": "This action will create a new document in the Drafts app using the text from the selected graphic.", "label": "1Writer • New Document with Graphic Text", "shortLabel": "1Writer Doc" }*/ var _ = function(){ var action = new PlugIn.Action(function(selection, sender){ // action code // selection options: canvas, document, graphics, lines, solids, view graphic = selection.solids[0] encodedStr = encodeURIComponent(graphic.text) urlStr = "onewriter://x-callback-url/create?text=" + encodedStr url = URL.fromString(urlStr) url.call(function(result){console.log(result)}) }); action.validate = function(selection, sender){ // validation code // selection options: canvas, document, graphics, lines, solids, view if(selection.solids.length === 1 && selection.solids[0].text != ''){ return true } else { return false } }; return action; }(); _;
graphic = document.windows[0].selection.solids[0] encodedStr = encodeURIComponent(graphic.text) urlStr = "onewriter://x-callback-url/create?text=" + encodedStr url = URL.fromString(urlStr) url.call(function(result){console.log(result)})
UNDER CONSTRUCTION

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

DISCLAIMER