Merging (or importing OO documents)

OmniOutliner 5 Pro (5.11.1) on macOS 12.6.1

Is it possible to combine multiple OO documents into one, please?

I am aware of the Window > Merge option; useful though this is, it only arranges open documents in the same window.

I want to permanently merge half a dozen .ooutline files into one, also combining - that is, not duplicating or otherwise ‘compromising’ - the styles and customizations which I have set; these are identical for all documents.

TIA for any suggestions :-)

1 Like

OmniOutliner has an applescript ‘import’ command which can insert one document into another. You need to specify a location within the destination document.

import to after last child

For whatever reason, it works with ‘children’ rather than the more obvious ‘rows’. Here are some simple examples that import some documents. Note that with multiple imports, the prior imports are included when determining where subsequent imports are deposited.

tell application "OmniOutliner"
	-- specify files to import	
	set imp1 to (path to desktop as text) & "testo1.ooutline" as alias
	set imp2 to (path to desktop as text) & "testo2.ooutline" as alias
	
	-- import above into document
	tell document "desto" to import imp1 to before first child -- to top of document
	tell document "desto" to import imp2 to after last child -- to bottom of document
	tell document "desto" to import imp2 to after child 2 -- occurs after prior imports
end tell

And here, importing a list of documents.

tell application "Finder" to set oList to (files of desktop whose name begins with "test" and kind is "OmniOutliner Document") as alias list

tell application "OmniOutliner"
	tell document "desto"
		repeat with iDoc in oList -- each doc to import
			import iDoc to after last child
		end repeat
	end tell
end tell

It should maintain the text/row styles from the source document although I don’t know how it handles named styles.

1 Like

Additionally, you can exercise some control over where the imports are deposited.

Here, the script imports the odd documents to the top and even documents to the bottom, leaving the original doc’s rows in the middle.

tell application "Finder" to set oList to (files of desktop whose name begins with "test" and kind is "OmniOutliner Document") as alias list

-- import docs — odd before first, even after last
tell application "OmniOutliner"
	tell document "desto"
		
		repeat with x from 1 to (length of oList)
			if x mod 2 is 1 then
				import item x of oList to before first child -- odd before
			else
				import item x of oList to after last child -- even after
			end if
		end repeat
		collapseAll children -- Collapse top children
		
	end tell
end tell

And finally, this script will take a list of files and import them in order, to after the corresponding child in the destination document and then indent them to make each level 2 (i.e. a subsection). So if you imported four documents, each would be inserted beneath one of the first four children. It works by cycling through each child id from before the import because while the child’s index may change after each import, the child id does not.

tell application "Finder" to set oList to (files of desktop whose name begins with "test" and kind is "OmniOutliner Document") as alias list

-- Import docs to after each child
tell application "OmniOutliner"
	set cc to 0 -- counter to track original children
	
	tell document "desto"
		collapseAll children
		set coldList to id of children -- list of document's original children
		-- import list of docs
		repeat with iDoc in oList -- cycle through import files
			set cc to cc + 1
			import iDoc to after child id (contents of item cc of coldList)
		end repeat
		
		-- cycle through newly imported children		
		set afterList to id of children -- all children after import
		
		repeat with eaChild in afterList
			if eaChild is not in coldList then -- indent if not original child
				indent row id (contents of eaChild) -- indent newly added children
			end if
		end repeat
		collapseAll (rows whose level is 2)
	end tell
end tell
1 Like

Thanks very much, @Mockman !

I really appreciate all these suggestions :-)

In my case I have seven OO Pro 5 (.ooline) files which need to emerged into one - all styles, rows and hierarchies intact.

I could treat the first file as the parent and try to adapt the scripts you kindly posted. But I’m not clear where to start and with which one.

I do need to preserve all my formatting and styles etc.

If you have a simple one-off script which will run without my having to experiment too much (not an AS expert), that would really help, please.

You probably want to go with the second example then. Try this:

First, make a copy of each of your files – never test automation with your only copy. Make a folder on your desktop (e.g. ‘collection’) and put the copies in there. You don’t need to open any of them. Then run this in Script Editor:

set collFolder to (path to desktop) & "collection:" as text
tell application "Finder"
	set oList to (files of folder collFolder whose kind is "OmniOutliner Document") as alias list
end tell

tell application "OmniOutliner"
	open item 1 of oList
	delay 1
	tell document 1
		
		repeat with iDoc in (rest of oList) -- each doc to import
			import iDoc to after last child
		end repeat
		
		collapseAll
		select last child
		
	end tell
end tell

Basically, the script does the following:

  • Specifies that the documents are in the folder ‘collection’ that is on the desktop
  • Makes a list of the omnioutliner files that are in that folder
  • Omnioutliner then opens the first file in the list and pauses for a second
  • It then cycles through the rest of the list and imports each file’s contents to the bottom of the document it just opened
  • Once that is complete, it collapses all of the rows and selects the last row. I include this because when you import the contents of all of the files, they will initially appear in a jumbled order but once you select something, they will order themselves visually.

A couple of caveats:

  • If your documents have different column layouts, e.g. one has 4 columns and another 3, then anything could happen.
  • Most styles and formats will carry over to the new document but font sizes may not.

You might want to test the script with two or three files rather than all seven. This would allow you to inspect the result and more easily see how the import went.

1 Like

Brilliant; thanks so much @Mockman!

Works perfectly :-)

I’ve been a Mac user since the mid 1990s. And a coder. But I just have never ‘clicked’ with AppleScript somehow.

I really appreciate the time and effort you will have put into this.

Thanks again!

1 Like

Glad it worked and glad to help.

1 Like