Process Graphic Text in Drafts
OmniGraffle → Drafts
Synopsis: This action will process the text of the selected graphic using a user-specified Drafts action.

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", "identifier": "com.omni-automation.drafts.process-graphic-text", "version": "1.0", "description": "This action will use the Drafts app to process the text of the selected graphic.", "label": "Drafts • Process Graphic Text", "shortLabel": "Process in Drafts" }*/ var _ = function(){ var action = new PlugIn.Action(function(selection, sender){ parametersForm = new Form() textInputField = new Form.Field.String( "textInput", "Drafts Action", null ) checkboxSwitch = new Form.Field.Checkbox( "checkboxSwitch", "Create new Draft", true ) parametersForm.addField(textInputField) parametersForm.addField(checkboxSwitch) // FORM PROMISE IS CREATED AND STORED WHEN DIALOG SHOWN formPrompt = "Enter the title of the Drafts action to execute:" buttonTitle = "Continue" formPromise = parametersForm.show(formPrompt, buttonTitle) // APPROVAL BUTTON WILL BE ACTIVATED ONLY IF TEXT ENTERED parametersForm.validate = function(formObject){ actionTitle = formObject.values["textInput"] status = (actionTitle && actionTitle.length > 0) ? true:false return status } // PROMISE FUNCTION CALLED UPON DIALOG APPROVAL formPromise.then(function(formObject){ actionTitle = formObject.values["textInput"] draftsActionTitle = encodeURIComponent(actionTitle) shouldCreateDraft = formObject.values["checkboxSwitch"] graphic = selection.solids[0] encodedStr = encodeURIComponent(graphic.text) segmentOptionA = "drafts5://x-callback-url/create?text=" segmentOptionB = "drafts5://x-callback-url/runAction?text=" firstSegment = (shouldCreateDraft) ? segmentOptionA : segmentOptionB urlStr = firstSegment + encodedStr + "&action=" + draftsActionTitle console.log(urlStr) url = URL.fromString(urlStr) url.call(function(result){ console.log(result) }) }) // PROMISE FUNCTION CALLED UPON DIALOG CANCELLATION formPromise.catch(function(error){ console.log("form cancelled", error.message) }) }); action.validate = function(selection, sender){ return (selection.solids.length === 1 && selection.solids[0].text != '') }; return action; }(); _;
drafts-parameters-form

 01-10  Action metadata defines which Omni applications will load the action, as weel as the title of the action’s corresponding Automation Menu menu item.

 14  A new instance of the Form class is created and stored in the variable: parametersForm

 16-20  A new text input instance of the Form.Field class is created and stored in the variable: textInputField

 22-26  A new checkbox instance of the Form.Field class is created and stored in the variable: checkboxSwitch

 28-29  The addField(…) function of the Form class is used to add the form elements to the form.

 32  The text for the prompt displayed in the form dialog is stored in the variable: formPrompt

 33  The title for the approval button displayed in form dialog is stored in the variable: buttonTitle

 34  The show(…) function of the Form class is used to display form in either a document sheet (macOS) or an overlay dialog (iOS, iPadOS). The result of the form display is an instance of the JavaScript Promise class that is stored in the variable: formPromise

 37-41  The validation property of the form is a function that examines the passed-in form object to determine if text has been entered in the text input field. If text has been entered by the user, the approval button is enabled.

 44-59  The then(…) function of the Promise class is executed when the approval button in the form dialog is pressed by the user.

 45  The string value of the text input when the dialog was approved is extracted from the passed-in form object using the identifier key for the form element: textInput

 46  The user-provided Drafts action title is encoded for inclusion in a URL.

 47  The boolean value of the checkbox when the dialog was approved is extracted from the passed-in form object using the identifier key for the form element: checkboxSwitch

 48-49  The graphic text of the selected graphic object is extracted and encoded for inclusion in a URL.

 50  The Drafts application supports two URL parameters for indicating how the passed textual data is to be processed: one creates a new draft (/create), and the other (/runAction) does not. A URL opening for each option is stored in its corresponding variable.

 52  A JavaScript ternary statement is used to return one of the stored URL opening based upon the boolean value of the dialog checkbox.

 53  A URL string targeting the Drafts application is constructed from the segments.

 55  A URL object is created from the URL string.

 X  The call(…) function of the URL class is used to execute the url object.

 62-64  The catch(…) function of the Promise class is executed if the form dialog is canceled by the user.

 68-70  The value of the action’s validation property is a function that returns a value of true only if a single solid containing text is selected in the OmniGraffle document.

The following video shows the Omni Automation action in use to AirDrop the graphic text to a local computer:

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