Export OmniOutliner document to Markdown

OmniOutliner is one of my favourite applications. I use it on the Mac and iPad for a vast array of tasks. Next to Mail, Safari, BBEdit and Xcode, its my most used app.

While OmniOutliner provides a built-in method of exporting outlines to Markdown, I find that I often need to export my outlines in specific ways. Using my MarkdownLib library, combined with OmniOutliner’s superb scripting interface, you have full control over Markdown generation.

NOTE: Both MarkdownLib and MarksLib are needed to run this example script.

Lets start with this simple OmniOutliner document:

We can run this script to iterate over the selected rows and generate Markdown:

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
use MarksLib : script "MarksLib" version "1.0"
use MarkdownLib : script "MarkdownLib" version "1.0"

tell application "OmniOutliner"
	tell first document
		set markdownText to {}
		
		repeat with aRow in (get selected rows)
			set targetRow to contents of aRow
			set end of markdownText to MarkdownLib's richTextToMarkdown(a reference to topic of targetRow)
			
			if targetRow's note is not "" then
				set end of markdownText to MarkdownLib's richTextToMarkdown(a reference to rich text of note cell of targetRow)
			end if
		end repeat
		
		set markdownText  to MarksLib's |join|(markdownText, return & return)
		my viewMarkdown(markdownText)
	end tell
end tell


property gFileNumber : 0

on viewMarkdown(markdownText)
	local filePath
	
	--	Display the Markdown - using MacDown (https://macdown.uranusjr.com) in my case
	set gFileNumber to gFileNumber + 1
	set filePath to "~/Desktop/text-" & gFileNumber & ".md"
	
	MarksLib's writeToFile(filePath, markdownText)
	tell application "Finder"
		open MarksLib's makeFileReference(filePath)
	end tell
end viewMarkdown

The resulting Markdown looks like this:

Here is the sample OmniOutliner document and the script shown above:

OmniOutlinerMarkdownDemo.zip (248.0 KB)

1 Like