Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Draft

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

Index

Constructors

constructor

Date Properties

createdAt

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

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.

Location Properties

createdLatitude

createdLatitude: number

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

createdLongitude

createdLongitude: number

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

modifiedLatitude

modifiedLatitude: number

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

modifiedLongitude

modifiedLongitude: number

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

Other Properties

content

content: string

The full text content.

Readonly displayTitle

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

isArchived: boolean

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

isFlagged

isFlagged: boolean

Current flagged status.

isTrashed

isTrashed: boolean

Is the draft currently in the trash.

languageGrammar

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

The preferred language grammar (syntax) to use for the draft. Can be any valid installed language grammar.

Readonly lines

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');

Readonly permalink

permalink: string

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

Readonly selectionLength

selectionLength: number

The length of the last text selection.

Readonly selectionStart

selectionStart: number

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

Readonly title

title: string

The first line.

Readonly uuid

uuid: string

Unique identifier.

Readonly versions

versions: Version[]

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

Tag Properties

Readonly tags

tags: string[]

Array of string tag names assigned.

Other Methods

append

  • append(text: string, separator?: string): void
  • 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

bodyPreview

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

    Parameters

    • maxLength: number

    Returns string

prepend

  • prepend(text: string, separator?: string): 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

saveVersion

  • saveVersion(): any
  • Create a version in the version history representing the current state of the draft.

    Returns any

update

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

    Returns void

Static create

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

    Returns Draft

Querying Methods

Static find

  • find(uuid: string): Draft
  • Find an existing draft based on UUID.

    Parameters

    • uuid: string

    Returns Draft

Static query

  • query(queryString: string, filter: "inbox" | "archive" | "flagged" | "trash" | "all", tags: string[], omitTags: string[], sort: "created" | "modified" | "accessed", sortDescending: boolean, sortFlaggedToTop: boolean): 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" | "archive" | "flagged" | "trash" | "all"

      Filter by one of the allowed values

    • tags: string[]

      Results will only include drafts with one or more of these 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[]

Static queryByTitle

  • queryByTitle(title: string): 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

addTag

  • addTag(tag: string): void
  • Assign a tag

    Parameters

    • tag: string

    Returns void

hasTag

  • hasTag(tag: string): boolean
  • Check whether a tag is currently assigned to the draft.

    Parameters

    • tag: string

    Returns boolean

removeTag

  • removeTag(tag: string): void
  • Remove a tag if it is assigned to the draft.

    Parameters

    • tag: string

    Returns void

Static recentTags

  • recentTags(): string[]
  • Return array of recently used tags. Helpful for building prompts to select tags.

    Returns string[]

Template Methods

getTemplateTag

  • getTemplateTag(tagName: string): string
  • Get the current value of a custom template tag.

    Parameters

    • tagName: string

    Returns string

processTemplate

  • processTemplate(template: string): string
  • Runs the template string through the template engine to evaluate tags (like <a href="draft.html#title">title</a>, <a href="gmailmessage.html#body">body</a>).

    Parameters

    • template: string

    Returns string

setTemplateTag

  • setTemplateTag(tagName: string, value: string): void
  • 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.

    Parameters

    • tagName: string
    • value: string

    Returns void

Generated using TypeDoc