New Drafts Doc with Text from Outline
OmniOutliner → Drafts
Synopsis: This Omni Automation script extracts the text of the outline rows to create a new paragraph-delimited document in Drafts.

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

/*{ "type": "action", "targets": ["omnioutliner"], "author": "Otto Automator", "description": "This action will create a new document in the Drafts app using the text from the outline.", "label": "Drafts • New Draft with Outline Text", "shortLabel": "Drafts Doc" }*/ var _ = function(){ var action = new PlugIn.Action(function(selection, sender){ // action code // selection options: columns, document, editor, items, nodes, outline, styles var alert = new Alert("Item Spacing", "Use a single or double space between top-level items?") alert.addOption("Single") alert.addOption("Double"){ if (result == 0){itemSpacer = ""} else {itemSpacer = "\n"} var topics = new Array() var indent = "\t" rootItem.descendants.forEach(function(item,index){ level = item.level if (level === 1){ if (index === 0){ itemString = item.topic } else { itemString = itemSpacer + item.topic } } else { itemString = indent.repeat(level-1) + item.topic } topics.push(itemString) }) outlineText = topics.join("\n") encodedStr = encodeURIComponent(outlineText) urlStr = "drafts5://x-callback-url/create?text=" + encodedStr url = URL.fromString(urlStr){console.log(result)}) }) }); action.validate = function(selection, sender){ // validation code // selection options: columns, document, editor, items, nodes, outline, styles if(rootItem.descendants.length > 0){return true} else {return false} }; return action; }(); _;

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

 42-46  The action validation routine determines the document conditions under which the action becomes available in the Automation menu. In this case, if the outline contains one or more rows.

 10-40  The code executed when the action is triggered.

 14-17  Create and display an alert with options for the user to indicate whether a single or double space is to be used between top-level items.

 18-31  Create an array containing the topic column text from the outline rows. IMPORTANT: this script is designed to be used with single-column outlines.

 34  Convert the array of row content into a single text string using the basic JavaScript join() method..

 35  Use the standard JavaScript encodeURIComponent() method to percent encode the outline string. Carriage returns and certain punctuation will be convert to percent codes for use in a URL.

 36  Using the Drafts URL API, append the encoded outline string to the end a URL command for creating a new document and setting its contents.

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

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

The following video shows the Omni Automation action in use:


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