The Draft object represents a single draft. When an action is run, the current draft is available as the global variable draft. Scripts can also create new drafts, access and set values, and update the draft to persist changes.

Example: Creating a draft

// create a new draft, assign content and save it
let d = new Draft();
d.content = "My new draft";
d.addTag("personal");
d.update();

Example: Querying drafts

// query a list of drafts in the inbox with the tag "blue"
let drafts = Draft.query("", "inbox", ["blue"])

Hierarchy

  • Draft

Constructors

Properties - ActionLog

Properties - Date

Properties - Deprecated

Properties - Location

Properties - Other

Properties - Tag

Properties - Version

Methods - Deprecated

Methods - Other

Methods - Querying

Methods - Tag

Methods - Template

Methods - Version

Constructors

  • Create new instance.

    Returns Draft

ActionLog Properties

actionLogs: ActionLog[]

Array of versions representing the entire saved version history for this draft.

Date Properties

createdAt: Date

Date the draft was created. This property is generally maintained by Drafts automatically and is it not recommended it be set directly unless needed to maintain information from an external source when importing.

modifiedAt: Date

Date the draft was last modified. This property is generally maintained by Drafts automatically and is it not recommended it be set directly unless needed to maintain information from an external source when importing.

Deprecated Properties

languageGrammar: "Plain Text" | "Markdown" | "Taskpaper" | "JavaScript" | "Simple List" | "MultiMarkdown" | "GitHub Markdown"

Deprecated

use syntax property.

Location Properties

createdLatitude: number

Numeric latitude where the draft was created. This value will be 0 if no location information was available.

createdLongitude: number

Numeric longitude where the draft was created. This value will be 0 if no location information was available.

modifiedLatitude: number

Numeric longitude where the draft was last modified. This value will be 0 if no location information was available.

modifiedLongitude: number

Numeric longitude where the draft was last modified. This value will be 0 if no location information was available.

Other Properties

content: string

The full text content.

displayTitle: string

Generally, the first line of the draft, but cleaned up as it would be displayed in the draft list in the user interface, removing Markdown header characters, etc.

isArchived: boolean

Is the draft current in the archive. If false, the draft is in the inbox.

isFlagged: boolean

Current flagged status.

isTrashed: boolean

Is the draft currently in the trash.

lines: [string]

The lines of content separated into an array on \n line feeds. This is a convenience method an equivalent to content.split('\n');

permalink: string

URL which can be used to open the draft. URLs are cross-platform, but specific to an individual user's drafts datastore.

selectionLength: number

The length of the last text selection.

selectionStart: number

The index location in the string of the beginning of the last text selection.

syntax?: Syntax

The syntax definition used when displaying this draft in the editor.

title: string

The first line.

uuid: string

Unique identifier.

Tag Properties

tags: string[]

Array of string tag names assigned.

Version Properties

versions: Version[]

Array of versions representing the entire saved version history for this draft.

Deprecated Methods

  • Deprecated

    use Tag.recentTags() instead.

    Returns string[]

Other Methods

  • Append text to the end of the draft's content. This is a convenience function.

    Parameters

    • text: string

      The text to append

    • Optional separator: string

      An optional separator string to use between content and added text. Defaults to a single line feed.

    Returns void

  • Return the a trimmed display version of the "body" of the draft (content after first line), similar to what is displayed as a preview in the draft list._

    Parameters

    • maxLength: number

    Returns string

  • Insert text into the draft's content at the line indicated. This is a convenience function.

    Parameters

    • text: string

      The text to in

    • line: number

      The index of the line number at which to insert the text. Line numbers are zero-based, so 0 is the first line. Drafts will range-check the line.

    Returns void

  • Prepend text to the beginning of the draft's content. This is a convenience function.

    Parameters

    • text: string

      The text to prepend

    • Optional separator: string

      An optional separator string to use between content and added text. Defaults to a single line feed.

    Returns void

  • Provide standard object representation of draft, compatible with JSON.stringify.

    Returns object

  • Save changes made to the draft to the database. update() must be called to save changes made to a draft.

    Returns void

  • Create a new draft object. This is an in-memory object only, unless "update()" is called to save the draft.

    Returns Draft

Querying Methods

  • Find an existing draft based on UUID.

    Parameters

    • uuid: string

    Returns Draft

  • Perform a search for drafts and return an array of matching draft objects.

    Parameters

    • queryString: string

      Search string, as you would type in the search box in the draft list. Will find only drafts with a matching string in their contents. Use empty string ("") not to filter.

    • filter: "inbox" | "flagged" | "archive" | "trash" | "all"

      Filter by one of the allowed values

    • tags: string[]

      Results will only include drafts with all the listed tags assigned.

    • omitTags: string[]

      Results will omit drafts with any of these tags assigned.

    • sort: "created" | "modified" | "accessed"
    • sortDescending: boolean

      If true, sort descending. Defaults to false.

    • sortFlaggedToTop: boolean

      If true, sort flagged drafts to beginning. Defaults to false.

    Returns Draft[]

  • Search for drafts containing the title string in the first line of their content. This mimics the logic used by the /open?title=Title URL scheme to locate drafts by title when triggering embedded cross-links.

    Parameters

    • title: string

    Returns Draft[]

Tag Methods

  • Assign a tag

    Parameters

    • tag: string

    Returns void

  • Check whether a tag is currently assigned to the draft.

    Parameters

    • tag: string

    Returns boolean

  • Remove a tag if it is assigned to the draft.

    Parameters

    • tag: string

    Returns void

Template Methods

  • Get the current value of a custom template tag.

    Parameters

    • tagName: string

    Returns string

  • Runs the template string through the Mustache template engine to evaluate tags. Allows additional values and partials to be provided to the context.

    Parameters

    • template: string

      Template string

    • additionalValues: Object

      An object containing additional values you wish to make available in the Mustache context.

    • partials: Object

      An object containing string keys and values which will contain additional templates you which to make available for use as partials and layouts.

    Returns string

  • Runs the template string through the Drafts Template engine to evaluate tags.

    Parameters

    • template: string

    Returns string

  • Set a custom template tag value for use in templates. For example, calling setTemplateTag("mytag", "mytext") will create a tag [[mytag]], which subsequent action steps in the same action can use in their templates. These values are also available in Mustache templates, but as {{mytag}}.

    Parameters

    • tagName: string
    • value: string

    Returns void

Version Methods

  • Create a version in the version history representing the current state of the draft.

    Returns any

Generated using TypeDoc