Drafts Reference


A global “editor” object is available in all action scripts. This object allows manipulation of the main editing window in Drafts, altering the text, text selections, or loading a different draft into the editor, etc.

Typically scripting actions that work like custom keyboard commands and similar will utilize the editor functions to manipulate text.

NOTE: Generally speaking, editor methods are best used for quick text manipulations of the type used in the extended keyboard. Most substantial updates to draft content are better applied using the draft object.

Instance Properties

Instance Functions


var sel = editor.getSelectedText(); // retrieve selected text
var selRange = editor.getSelectedRange(); // retrieve range of that selection

if (!sel || sel.length == 0) {
  // if there was no selection, insert Markdown bold (**)
  // update the selected range to the end of the inserted text
else {
  // If there was a selection, wrap that text with Markdown bold (**) and replace selection
  // Update the selected range to the end of the inserted text