Last active
March 12, 2021 17:21
-
-
Save juandesant/34cdf64845b5d4c78f1caa5d9ca5f05e to your computer and use it in GitHub Desktop.
This script takes selected rows in OmniOutliner, and tries to split topics that have multiple lines into multiple rows, and leaves one-liner items alone.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Based on information provided on | |
// https://omni-automation.com/omnioutliner/item.html | |
// Get selected nodes in foremost window (editors[0]) | |
var nodes = document.editors[0].selectedNodes | |
// Split all selected topics in paragraphs | |
nodes.forEach( | |
function(node) { | |
// for each individual node | |
var selectedItem = node.object | |
// we get the parent so that we keep the relationship | |
var selectedItemParent = selectedItem.parent | |
// item.topic contains the outliner's text | |
var selectedTopics = selectedItem.topic | |
// split the topic in multiple lines per \n character | |
var splitTopics = selectedTopics.split("\n") | |
// for topics with more than one entry after splitting | |
if (splitTopics.length > 1) { | |
splitTopics.forEach( | |
function(theTopic) { | |
selectedItemParent.addChild( | |
selectedItem.before, | |
function(item) { | |
item.topic = theTopic | |
} | |
) | |
} | |
) | |
// we remove the item after having added the split topics | |
selectedItem.remove() | |
} | |
} | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment