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.
Text of the Top-Level Entries of an Outline | ||
01 | // returns text of combined children entries | |
02 | function rootChildrenText(){ | |
03 | topics = new Array() | |
04 | rootItem.children.forEach(function(item){ | |
05 | topics.push(item.topic) | |
06 | }) | |
07 | return topics.join('\n') | |
08 | } | |
09 | rootChildrenText() |
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.
Tab-Indented Text of the full Outline | ||
01 | // returns tab-delimited text of outline | |
02 | function rootDescendentsText(){ | |
03 | textBlock = "" | |
04 | rootItem.descendents.forEach(function(item){ | |
05 | textBlock = textBlock + "\t".repeat(item.level-1) + item.topic + "\n" | |
06 | }) | |
07 | return textBlock | |
08 | } | |
09 | rootDescendentsText() |
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.
Import Outline Text into Selected Shape | ||
01 | /*{ | |
02 | "type": "action", | |
03 | "targets": ["omnigraffle"], | |
04 | "author": "Otto Automator", | |
05 | "identifier": "com.omni-automation.og.import-outline-to-selected-shape", | |
06 | "version": "1.0", | |
07 | "description": "Will import the topic text of the current outline document into the selected solid.", | |
08 | "label": "Import Outline Topics", | |
09 | "shortLabel": "Import Outline Topics" | |
10 | }*/ | |
11 | (() => { | |
12 | var action = new PlugIn.Action(function(selection, sender){ | |
13 | // action code | |
14 | ||
15 | var checkSwitchField = new Form.Field.Checkbox( | |
16 | "shouldReplaceText", | |
17 | "Replace existing text in the shape", | |
18 | null | |
19 | ) | |
20 | ||
21 | var inputForm = new Form() | |
22 | inputForm.addField(checkSwitchField) | |
23 | var formPrompt = "Form prompt:" | |
24 | var buttonTitle = "Continue" | |
25 | formPromise = inputForm.show(formPrompt,buttonTitle) | |
26 | ||
27 | inputForm.validate = function(formObject){ | |
28 | return true | |
29 | } | |
30 | ||
31 | formPromise.then(function(formObject){ | |
32 | var shouldReplaceText = formObject.values['shouldReplaceText'] | |
33 | ||
34 | // THE FUNCTION TO BE EXECUTED BY THE TARGET APP | |
35 | function targetAppFunction(){ | |
36 | try { | |
37 | textBlock = "" | |
38 | rootItem.descendents.forEach(item => { | |
39 | textBlock = textBlock + "\t".repeat(item.level-1) + item.topic + "\n" | |
40 | }) | |
41 | return textBlock | |
42 | } | |
43 | catch(error){ | |
44 | console.error("An error occurred.") | |
45 | throw error | |
46 | } | |
47 | } | |
48 | ||
49 | // CREATE SCRIPT URL WITH FUNCTION | |
50 | var scriptURL = URL.tellFunction( | |
51 | "omnioutliner", | |
52 | targetAppFunction, | |
53 | null | |
54 | ) | |
55 | ||
56 | // CALL THE SCRIPT URL, PROCESS RESULTS OR ERROR | |
57 | scriptURL.call(reply => { | |
58 | if (typeof reply === "object"){ | |
59 | reply = reply["result"] | |
60 | } | |
61 | // REPLACE/APPEND TEXT | |
62 | var solid = selection.solids[0] | |
63 | var currentSize = solid.textSize | |
64 | ||
65 | if(shouldReplaceText){ | |
66 | solid.text = reply | |
67 | } else { | |
68 | solid.text = solid.text + reply | |
69 | } | |
70 | solid.textSize = currentSize | |
71 | }, function(err){ | |
72 | // PROCESS SCRIPT ERROR | |
73 | new Alert("SCRIPT ERROR", err.errorMessage).show() | |
74 | console.error(err) | |
75 | }) | |
76 | ||
77 | }) | |
78 | ||
79 | }); | |
80 | ||
81 | action.validate = function(selection, sender){ | |
82 | // validation code | |
83 | return (selection.solids.length === 1) | |
84 | }; | |
85 | ||
86 | return action; | |
87 | })(); |
This webpage is in the process of being developed. Any content may change and may not be accurate or complete at this time.