Process Graphic Text
OmniGraffle → Drafts → OmniGraffle
Synopsis: An example of “round-tripping” data, this workflow copies the text from the selected OmniGraffle graphic to a new Drafts document, and processes the transfered text with a Drafts action that ends by replacing the text in the graphic with the processed text.

An exciting feature of the Drafts app on iOS, is its ability to create and run processing workflows with its documents.

By including the Drafts “action” URL parameter in the URL targeting the Drafts application, Omni Automation scripts can not only create new Drafts documents with content from OmniGraffle and OmniOutliner documents, but can also trigger the processing (in Drafts) of the passed content as well. And optionally, the results of the Drafts workflows can be returned to the originating OmniGraffle or OmniOutliner document!

OmniGraffle → Drafts

The following action is used to pass the text content of the selected OmniGraffle graphic to Drafts, and then trigger the execution of a Drafts action:

/*{ "type": "action", "targets": ["omnigraffle"], "author": "Otto Automator", "description": "This action will use the Drafts app to capitalize the text of the selected graphic.", "label": "Drafts • Capitalize Graphic Text", "shortLabel": "Cap using Drafts" }*/ 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) draftsActionTitle = 'Capitalize Graphic Text' draftsActionTitle = encodeURIComponent(draftsActionTitle) urlStr = "drafts5://x-callback-url/create?text=" + encodedStr + "&action=" + draftsActionTitle 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; }(); _;

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

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

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

 14  The text of the selected OmniGraffle graphic is percent encoded for inclusion in a URL created using the Draft URL API that targets the Drafts app.

 15-16  The name of the Drafts action to be called is percent encoded for inclusion in a URL targeting the Drafts app.

 17  The URL targeting the Drafts app with instructions to create a new document containing the passed text, and then run the indicated action.

 18  The url string is converted into a URL object.

 19  The URL is called.

Drafts → OmniGraffle

The Drafts action triggered by the URL in OmniGraffle action contains two steps:

capitalize-action drafts-action-script

Video

The following video demonstrates how the technique shown in the example above, can be used to transfer text from an OmniGraffle graphic to a new Drafts document, process the transfered text with Drafts actions, and then replace the original text in the graphic with the processed text, and delete the created Drafts document:

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