MarkdownLib on GitHub


(Mark Alldritt) #1

MarkdownLib is a small AppleScript library for converting bodies of styled text into Markdown and is part of my AppleScript Libraries repository on GitHub.

The library can be used with any application that supports the Text Suite (the Text Suite’s attribute run object in particular). This includes TextEdit, all of the OmniGroup’s applications, and many others. I’m a heavy user of OmniOutliner and MarkdownLib can be used to covert an outline and its notes into Markdown. Sadly, Apple’s Pages does not provide an attribute run object.


Download and run this script application:

Install (71.1 KB)

NOTE: MarksLib is required for the example scripts that follow. MarkdownLib can be used without MarksLib.

Installation (manually)

Enter the following commands in the Terminal application to install the latest version of MarkdownLib and MarksLib on your machine:

curl | osacompile -o ~/Library/Script\ Libraries/MarkdownLib.scpt
curl | osacompile -o ~/Library/Script\ Libraries/MarksLib.scpt


MarkdownLib provides the following handlers:


The richTextToMarkdown(richTextReference) handler converts the referenced rich text object into a Markdown string and returns it as the handler’s result.


This example script converts the contents of a TextEdit document to Markdown.

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

tell application "TextEdit"
	set theName to name of document 1
	set theMarkdown to MarkdownLib's richTextToMarkdown(a reference to document 1)
end tell

MarksLib's writeToFile("~/Desktop/" & theName & ".md", theMarkdown) (1.4 KB)

Open this sample document in TextEdit.

Running the AppleScript code shown above produces the following output (viewed in MacDown):

Export OmniOutliner document to Markdown
(Mark Alldritt) #2

2 posts were merged into an existing topic: MarksLib on GitHub