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",
"identifier": "com.omni-automation.export-outline-to-drafts-as-plain-text",
"version": "1.0",
"description": "This action will create a new document in the Drafts app with the contents of the outline in plain text format.",
"label": "Drafts • Export to Drafts as Plain Text Outline",
"shortLabel": "Export to Drafts"
}*/
var _ = function(){
var action = new PlugIn.Action(function(selection, sender){
// action code
fileTypeID = "public.plain-text"
baseName = "Outline"
wrapperPromise = document.makeFileWrapper(baseName, fileTypeID)
wrapperPromise.then(function(wrapper){
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)})
})
wrapperPromise.catch(function(err){
console.error(err.message)
})
});
action.validate = function(selection, sender){
// validation code
return (rootItem.descendants.length > 0)
};
return action;
}();
_;
01-10 The action metadata. Edit the author and label tags to suit your purposes.
33-36 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.
11-40 The action code that gets executed when the action is triggered.
15 The file type identifier for plain text export. To export in OPML format (Outline Processor Markup Language), change this to either "com.apple.news.opml" or "org.opml.opml"
17 Use the makeFileWrapper(…) function of the Document class to create a virtual plain-text export object (FileWrapper). The result of the command is a JavaScript Promise object which is stored in the variable: wrapperPromise
19-25 The then(…) function of the Promise class is called on the stored promise when the file wrapper has been created, and is passed into the processing function.
20 Get the text contents of the virtual plain-text export object (wrapper) and store it in the variable: outlineText
21 Use the standard JavaScript method encodeURIComponent() to percent encode the graphic’s text and store the result in the variable: encodedStr
22 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.
23 Convert the URL string into an instance of the URL object class.
24 Use the call() method to execute the URL object.
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.