Export Outline to New Draft
OmniOutliner → Drafts
Synopsis: Create a new Draft document using the contents of the OmniOutliner outline exported as plain-text format.

In this OmniOutliner action plugin, the FileWrapper class is used to create a new Drafts document containing the contents of a virtual export of the current OmniOutliner outline in plain-text format.

A list of the available OmniOutliner export (FileWrapper) types is available here.

/*{ "type": "action", "targets": ["omnioutliner"], "author": "Otto Automator", "description": "This action will create a new document in the Drafts app with the contents of the outline in plain text format.", "label": "Drafts • New Draft with Plain Text Outline", "paletteLabel": "Drafts Doc" }*/ var _ = function(){ var action = new PlugIn.Action(function(selection, sender){ // action code // selection options: columns, document, editor, items, nodes, outline, styles wrapper = document.fileWrapper('public.plain-text') outlineText = wrapper.contents.toString() encodedStr = encodeURIComponent(outlineText) 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: 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.

 21-25  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-19  The action code that gets executed when the action is triggered.

 13  Create a virtual plain-text export object (FileWrapper) and store it in the variable: wrapper

 14  Get the text contents of the virtual plain-text export object (FileWrapper) and store it in the variable: outlineText

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

 16  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.

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

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

plain-text

TIP: to view the document contents as plain text in the console, use this script statement:

document.fileWrapper('public.plain-text').contents.toString()
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