Using one of the JavaScript action templates , this script converts the tab-indented paragraphs in a draft to added hierarchical rows in the current OmniOutliner outline document.
(() => {
// OmniOutliner JS Context
function newOutline(arrayOfTabIndentedStrings){
var priorLevel = null
var priorItem = null
var counter
arrayOfTabIndentedStrings.forEach(function(p){
// count the leading tab characters
counter = 0
str = p
while (str.indexOf(' ') != -1) {
counter = counter + 1
str = str.substr(1);
}
itemLevel = counter
// add item based upon level
if (priorLevel === null){
priorItem = rootItem.addChild(
null,
function(item){item.topic = p}
)
priorLevel = 0
} else if (itemLevel === 0){
priorItem = rootItem.addChild(
null,
function(item){item.topic = p}
)
priorLevel = 0
} else if (itemLevel === priorLevel){
priorItem = priorItem.parent.addChild(
null,
function(item){item.topic = p.trim()}
)
priorLevel = priorLevel
} else if (itemLevel > priorLevel){
priorItem = priorItem.addChild(
null,
function(item){item.topic = p.trim()}
)
priorLevel = priorItem.level - 1
} else if (itemLevel < priorLevel){
delta = priorLevel - itemLevel
if (delta === 1){
itemParent = priorItem.parent.parent
priorItem = itemParent.addChild(
null,
function(item){item.topic = p.trim()}
)
priorLevel = priorLevel - 2
} else if (delta === 2){
itemParent = priorItem.parent.parent.parent
priorItem = itemParent.addChild(
null,
function(item){item.topic = p.trim()}
)
priorLevel = priorLevel - 3
} else if (delta === 3){
itemParent = priorItem.parent.parent.parent.parent
priorItem = itemParent.addChild(
null,
function(item){item.topic = p.trim()}
)
priorLevel = priorLevel - 4
}
}
})
};
const arrayOfTabIndentedStrings = editor.getText().split('\n');
app.openURL(
'omnioutliner://localhost/omnijs-run?script=' +
encodeURIComponent(
'(' + newOutline + ')' +
'(' + JSON.stringify(arrayOfTabIndentedStrings) + ')'
)
);
})();
New Outline from Tabbed Paragraphs
Copy Script
01 (() => {
02
03 function newOutline (arrayOfTabIndentedStrings ){
04 var priorLevel = null
05 var priorItem = null
06 var counter
07 arrayOfTabIndentedStrings .forEach (function (p ){
08
09 counter = 0
10 str = p
11 while (str .indexOf (' ' ) != -1) {
12 counter = counter + 1
13 str = str .substr (1);
14 }
15 itemLevel = counter
16
17 if (priorLevel === null ){
18 priorItem = rootItem .addChild (
19 null ,
20 function (item ){item .topic = p }
21 )
22 priorLevel = 0
23 } else if (itemLevel === 0){
24 priorItem = rootItem .addChild (
25 null ,
26 function (item ){item .topic = p }
27 )
28 priorLevel = 0
29 } else if (itemLevel === priorLevel ){
30 priorItem = priorItem .parent .addChild (
31 null ,
32 function (item ){item .topic = p .trim ()}
33 )
34 priorLevel = priorLevel
35 } else if (itemLevel > priorLevel ){
36 priorItem = priorItem .addChild (
37 null ,
38 function (item ){item .topic = p .trim ()}
39 )
40 priorLevel = priorItem .level - 1
41 } else if (itemLevel < priorLevel ){
42 delta = priorLevel - itemLevel
43 if (delta === 1){
44 itemParent = priorItem .parent .parent
45 priorItem = itemParent .addChild (
46 null ,
47 function (item ){item .topic = p .trim ()}
48 )
49 priorLevel = priorLevel - 2
50 } else if (delta === 2){
51 itemParent = priorItem .parent .parent .parent
52 priorItem = itemParent .addChild (
53 null ,
54 function (item ){item .topic = p.trim ()}
55 )
56 priorLevel = priorLevel - 3
57 } else if (delta === 3){
58 itemParent = priorItem .parent .parent .parent .parent
59 priorItem = itemParent .addChild (
60 null ,
61 function (item ){item .topic = p .trim ()}
62 )
63 priorLevel = priorLevel - 4
64 }
65 }
66 })
67 };
68
69 const arrayOfTabIndentedStrings = editor .getText ().split ('\n' );
70
71 app .openURL (
72 'omnioutliner://localhost/omnijs-run?script=' +
73 encodeURIComponent (
74 '(' + newOutline + ')' +
75 '(' + JSON .stringify (arrayOfTabIndentedStrings ) + ')'
76 )
77 );
78 })();
Your browser does not support the video tag.
PLAY
PAUSE
BACK
REWIND
TOPICS
Home
OmniGraffle
OmniOutliner
OmniPlan
OmniFocus
Drafts App
JavaScript Action Templates
New Draft with Graphic Text
New Draft with Outline Text
Export Outline to New Draft
Draft to Selected Graphic
Process Graphic Text
Append ¶’s to Outline
Prepend ¶’s to Outline
New Outline from Draft
The Business Letter
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
Mention of third-party websites and products is for informational purposes only and constitutes neither an endorsement nor a recommendation. OMNI-AUTOMATION.COM assumes no responsibility with regard to the selection, performance or use of information or products found at third-party websites. OMNI-AUTOMATION.COM provides this only as a convenience to our users. OMNI-AUTOMATION.COM has not tested the information found on these sites and makes no representations regarding its accuracy or reliability. There are risks inherent in the use of any information or products found on the Internet, and OMNI-AUTOMATION.COM assumes no responsibility in this regard. Please understand that a third-party site is independent from OMNI-AUTOMATION.COM and that OMNI-AUTOMATION.COM has no control over the content on that website. Please contact the vendor for additional information.