Drafts Scripting Reference


Drafts defines a single global “app” object which provides access to application level functions.

Instance Properties

Instance Functions


// open a URL
var url = "http://agiletortoise.com/";
var result = app.openURL(url);
// prompt user to select a draft...
var draft = app.selectDraft();
if (draft) { // make sure they didn't cancel
	// update draft as needed
// Process Markdown to HTML
var mmd = MultiMarkdown.create();
var html = mmd.render(draft.content);

// Wrap raw MMD output with HTML template with styles to set base fonts.
var template = "<html><style>body{font-family:'Helvetica';font-size:100%;}</style><body>[[content]]</body></html>"
var html = template.replace("[[content]]", html);

// Place in clipboard as rich-text
if (!app.htmlToClipboard(html)) {
	context.fail("Error rendering rich text from HTML.");