Import from OmniOutliner

In this section, the text of an outline in OmniOutliner can be retrieved and imported into the selected text box in an OmniGraffle document. The example begins with a look at two OmniOutliner functions for retrieving text from the current outline document.

Text of the Top-Level Entries of an Outline

The following function can be used to combine the text from the top-level outline items into a paragraph-delimited block of text.

function rootChildrenText(){ topics = new Array() rootItem.children.forEach(function(item){ topics.push(item.topic) }) return topics.join('\n') }

Tab-Indented Text of the full Outline

This OmniOutliner function will retrieve the text of the outline with tab indents to indicate the hierarchy of the outline elements.

function textOfFullOutline(){ textBlock = "" rootItem.descendents.forEach(function(item){ textBlock = textBlock + "\t".repeat(item.level-1) + item.topic + "\n" }) return textBlock }

Import Topic Text into Shape

The following plug-in uses the tellFunction() method of the URL class to send a script function to be executed by Omnioutliner, and return the resulting text content to the plug-in for insertion into the selected solid. The plug-in presents an action form dialog containing a checkbox option for replacing the existing text of the shape, otherwise the text will be retained and the derived text appended to the existing text.

/*{ "type": "action", "targets": ["omnigraffle"], "author": "Otto Automator", "identifier": "com.omni-automation.og.import-outline-to-selected-shape", "version": "1.0", "description": "Will import the topic text of the current outline document into the selected solid.", "label": "Import Outline Topics", "shortLabel": "Import Outline Topics" }*/ (() => { var action = new PlugIn.Action(function(selection, sender){ // action code var checkSwitchField = new Form.Field.Checkbox( "shouldReplaceText", "Replace existing text in the shape", null ) var inputForm = new Form() inputForm.addField(checkSwitchField) var formPrompt = "Form prompt:" var buttonTitle = "Continue" formPromise = inputForm.show(formPrompt,buttonTitle) inputForm.validate = function(formObject){ return true } formPromise.then(function(formObject){ var shouldReplaceText = formObject.values['shouldReplaceText'] // THE FUNCTION TO BE EXECUTED BY THE TARGET APP function targetAppFunction(){ try { textBlock = "" rootItem.descendents.forEach(item => { textBlock = textBlock + "\t".repeat(item.level-1) + item.topic + "\n" }) return textBlock } catch(error){ console.error("An error occurred.") throw error } } // CREATE SCRIPT URL WITH FUNCTION var scriptURL = URL.tellFunction( "omnioutliner", targetAppFunction, null ) // CALL THE SCRIPT URL, PROCESS RESULTS OR ERROR scriptURL.call(reply => { if (typeof reply === "object"){ reply = reply["result"] } // REPLACE/APPEND TEXT var solid = selection.solids[0] var currentSize = solid.textSize if(shouldReplaceText){ solid.text = reply } else { solid.text = solid.text + reply } solid.textSize = currentSize }, function(err){ // PROCESS SCRIPT ERROR new Alert("SCRIPT ERROR", err.errorMessage).show() console.error(err) }) }) }); action.validate = function(selection, sender){ // validation code return (selection.solids.length === 1) }; return action; })();
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