### Example Theme Colors Object Source: https://docs.getdrafts.com/docs/extending/development/theme-format An abbreviated example demonstrating the structure of a 'colors' object within a Drafts theme. This illustrates how different UI categories are organized and color values are assigned. ```json "colors": { "editor": { "foreground": "#000000", "background": "#FFFFFF", ... }, "interface": { "tint": "#538AEF", "tintAlternate": "#7892C4", ... } } ``` -------------------------------- ### Get lines with prefix using draft.linesWithPrefix Source: https://docs.getdrafts.com/changelog Returns an array of strings, where each string is a line from the draft that starts with the specified prefix. ```javascript draft.linesWithPrefix("-") // Returns an array of lines starting with "-" ``` -------------------------------- ### DateFormatter Custom Date Formatting Examples Source: https://docs.getdrafts.com/docs/actions/templates/drafts-templates Create custom date formats using DateFormatter strings. Strings starting with '~' ignore spacing and punctuation, letting the system determine localization. Strings starting with '=' maintain provided spacing and punctuation. ```text [[date|~yyyyMMdd]] ``` ```text [[date|~yyyyMMddHHmmss]] ``` ```text [[date|=dd.MM.yy]] ``` ```text [[date|=MMM d, h:mm a]] ``` -------------------------------- ### Basic Find and Replace Action Example Source: https://docs.getdrafts.com/docs/editor/find This action opens the standard find window. It is useful for quick searches within a draft. ```javascript { " கருவி " : "action", "name" : "Find in Draft...", "description" : "Opens the standard find window.", "script" : "editor.find()" } ``` -------------------------------- ### Advanced Search Query Examples Source: https://docs.getdrafts.com/changelog/changelog-ios Demonstrates advanced search query syntax for Drafts, including exact phrases, prefix searches, AND/OR operators, and regular expressions. ```text title:"My Draft" ``` ```text blue OR green ``` ```text blue red OR green ``` ```text /.*ABC.*/ ``` ```text /\d+/ ``` ```text /.*\[\[.*\]\].*/ ``` -------------------------------- ### Basic Tag Examples Source: https://docs.getdrafts.com/docs/misc/interact-scratchpad Demonstrates the basic format for using tags to identify contact information. Tags appear at the beginning of a line, followed by a colon and the value. ```text first: Joe title: Vice President phone-home: 888-555-1234 ``` -------------------------------- ### Get Action Source: https://docs.getdrafts.com/docs/automation/shortcuts-reference Retrieves an action. ```APIDOC ## Get Action ### Description Retrieves an action. ### Result * Found Action ``` -------------------------------- ### Configure Link Definitions Source: https://docs.getdrafts.com/docs/extending/development/syntax-format Define custom link formats using regular expressions and URL templates. This example shows how to create links for internal drafts, search, Google, Wikipedia, and Bear notes. ```json "linkDefinitions": [ { "enabled": true, "match": "(\[\[)((d|u|s|w|google|wikipedia|bear):(.+))(\]\])", "captures": { "key": "3", "value": "4", "link": "2", "prefix": "1", "suffix": "5" }, "templates": { "": "drafts://open?title=[[value]]&allowCreate=true", "d": "drafts://open?title=[[value]]&allowCreate=true", "u": "drafts://open?uuid=[[value]]", "s": "drafts://quickSearch?query=[[value]]", "w": "drafts://workspace?name=[[value]]", "google": "https://www.google.com/search?q=[[value]]", "wikipedia": "https://en.wikipedia.org/wiki/[[value]]", "bear": "bear://x-callback-url/open-note?title=[[value]]" }, "scopes": { "key": "text.bold", "value": "text.italic", "prefix": "markup", "suffix": "markup" } } ] ``` -------------------------------- ### Example Scopes Object in Drafts Theme Source: https://docs.getdrafts.com/docs/extending/development/theme-format Illustrates how to define font styles for various text scopes like normal text, headers, bold, and italic. Uses 'name' for display and 'settings' for font attributes. ```json "scopes": { "text.normal": { "name": "Normal Text", "settings": { "fontStyle": "", "foreground": "foreground" } }, "text.header": { "name": "Header", "settings": { "fontWeight": "bold", "foreground": "header" } }, "text.bold": { "name": "Bold", "settings": { "fontWeight": "bold", "foreground": "foreground" } }, "text.italic": { "name": "Italic", "settings": { "fontStyle": "italic", "foreground": "foreground" } }, ... } ``` -------------------------------- ### Create New Draft with AppleScript Source: https://docs.getdrafts.com/docs/automation/applescript.html This AppleScript example shows how to create a new draft within the Drafts application. It demonstrates setting the content, flagged status, and tags for the new draft. ```applescript tell application "Drafts" make new draft with properties {content: "My Draft Content", flagged: false, tag list: {"blue", "green"}} end tell ``` -------------------------------- ### Example 'static' Type Autocomplete Definitions Source: https://docs.getdrafts.com/docs/extending/development/syntax-format Autocomplete definitions for the 'static' type, providing a predefined list of suggestions triggered by '!!'. Includes dynamic date insertion via template tags. ```json "autocompleteDefinitions": [ { "trigger": "!!", "type": "static", "processTemplateTags": true, "items": [ { "label": "My First Item", "value": "My First Item", "prefix": "", "suffix": "" }, { "label": "Current Date", "value": "[[date|%Y-%m-%d]]", "prefix": "", "suffix": "" } ], "enabled": true } ] ``` -------------------------------- ### Accessing Configured Values in Scripts Source: https://docs.getdrafts.com/docs/actions/configuration.html Access configured values within a script by checking the `context.configuredValues` object. This example shows how to set a default value and override it if a configured value exists. ```javascript // setup a variable with a default value let markup = "_"; // check if a user-configured value is available and override if so... if (context.configuredValues["markupCharacter"]) { markup = context.configuredValues["markupCharacter"] } ``` -------------------------------- ### Submitting HTML Form Data to Drafts Source: https://docs.getdrafts.com/docs/actions/html-forms This example demonstrates serializing form data, sending it to Drafts using `Drafts.send()`, and then continuing the action. It includes helper functions for form serialization and submission. ```html
``` -------------------------------- ### Call Shortcut and Get Results with Shortcut Script Object Source: https://docs.getdrafts.com/changelog Use the `Shortcut.create` object to easily call a shortcut by name and pass draft content. Check the `run()` result and access the `result` property for the shortcut's output. ```javascript let shortcut = Shortcut.create("MY-SHORTCUT-NAME", draft.content) if (shortcut.run()) { // if here, the shortcut ran successfully // show an alert with the result text alert(shortcut.result) } ``` -------------------------------- ### Show Command Palette with Initial Query (Scripting) Source: https://docs.getdrafts.com/changelog This scripting function displays the command palette with an optional initial query. Ensure the `app.currentWindow` object is available before calling. ```javascript app.currentWindow.showCommandPalette(initialQuery) ``` -------------------------------- ### Bookmarklet JavaScript for Markdown Example Source: https://docs.getdrafts.com/docs/extensions/web-capture This raw JavaScript can be used as a starting point in a bookmarklet generator to customize how web content is captured into Drafts, including page title, URL, and selected text. ```javascript s=document.getSelection(); if (s && s != "") { s=` > ${s}`; } t=`[${document.title}](${location.href})`; u=`https://capture.getdrafts.com/?redirect=back&url=${encodeURIComponent(location.href)}&text=${encodeURIComponent(t)}${encodeURIComponent(s)}` document.location=u; ``` -------------------------------- ### Get Current Workspace Object Source: https://docs.getdrafts.com/changelog/changelog-mac Access the `app.currentWorkspace` property to get a Workspace object representing the current drafts list configuration. Primarily for read-only use. ```javascript app.currentWorkspace ``` -------------------------------- ### Open Quick Search via URL Action Source: https://docs.getdrafts.com/changelog/changelog-mac Use this URL action to open Drafts directly to the Quick Search interface. ```url /quickSearch?query= ``` -------------------------------- ### Launch Command Palette via URL Scheme Source: https://docs.getdrafts.com/changelog Use this URL scheme to launch the command palette directly. Ensure the query parameter is properly encoded if it contains special characters. ```url /commandPalette?query= ``` -------------------------------- ### Get Draft Source: https://docs.getdrafts.com/docs/automation/shortcuts-reference Retrieves a draft. ```APIDOC ## Get Draft ### Description Retrieves a draft. ### Result * Retreived Draft ``` -------------------------------- ### Create Draft with Optional Flags and Folders Source: https://docs.getdrafts.com/changelog Use the `/create` URL scheme to create new drafts. Optionally include `flagged` (true/false) and `folder` (inbox/archive) query arguments. ```url /create?flagged=true&folder=inbox ``` -------------------------------- ### Create New Draft with Syntax Source: https://docs.getdrafts.com/changelog/changelog-mac Use the `File > New with Syntax` menu option to create a new draft pre-assigned with a specific syntax. ```menu File > New with Syntax ``` -------------------------------- ### Get Workspace Source: https://docs.getdrafts.com/docs/automation/shortcuts-reference Retrieve a specific workspace. ```APIDOC ## Get Workspace ### Description Get workspace. ### Parameters * **Workspace** (Workspace) ### Result * Workspace ``` -------------------------------- ### Get Trimmed Body Preview in Drafts Source: https://docs.getdrafts.com/changelog/changelog-mac Use the `draft.bodyPreview(maxLength:)` function to get a trimmed version of the draft's body, similar to what's displayed in the draft list. This function removes the first line, trims whitespace, and truncates to the specified length. ```swift draft.bodyPreview(maxLength: 100) ``` -------------------------------- ### Show Quick Search via Scripting Source: https://docs.getdrafts.com/changelog/changelog-mac Call this scripting function to programmatically display the Quick Search interface, optionally with an initial query. ```javascript app.showQuickSearch(initialQuery) ``` -------------------------------- ### Get Drafts from Workspace Source: https://docs.getdrafts.com/docs/automation/shortcuts-reference Retrieve drafts from a specified workspace. ```APIDOC ## Get Drafts from Workspace ### Description Get drafts from workspace. ### Parameters * **Workspace** (Workspace) ### Result * Drafts ``` -------------------------------- ### Get Draft Versions Source: https://docs.getdrafts.com/docs/automation/shortcuts-reference Retrieves the version history of a draft. ```APIDOC ## Get Draft Versions ### Description Retrieves version history of a draft. ### Result * Draft Versions ``` -------------------------------- ### Open Workspace with Default Arguments Source: https://docs.getdrafts.com/changelog/changelog-mac Use the `/workspace` URL action with the `name=Default` argument to clear filters and load the default workspace. ```url /workspace?name=Default ``` -------------------------------- ### Get Current Draft Source: https://docs.getdrafts.com/docs/automation/shortcuts-reference Retrieve the active draft from the editor. ```APIDOC ## Get Current Draft ### Description Retrieve active draft from editor. ### Result * Current Draft ``` -------------------------------- ### Show HTML Preview with HTMLPreview.show() Source: https://docs.getdrafts.com/changelog/changelog-ios Utilize the `HTMLPreview` script object to display an HTML preview. The `show` method takes an HTML string as input and returns a boolean indicating success. ```javascript const preview = new HTMLPreview(); const success = preview.show("This is HTML content.
"); ``` -------------------------------- ### Get Draft by UUID Source: https://docs.getdrafts.com/docs/automation/shortcuts-reference Retrieves a draft using its unique identifier. ```APIDOC ## Get Draft by UUID ### Description Retrieves a draft using its unique identifier. ### Parameters * **UUID** (string) - Unique identifier of the draft. ### Result * Draft ``` -------------------------------- ### Get FileManager Base URL and Path Source: https://docs.getdrafts.com/changelog/changelog-mac Access the base URL or POSIX path for the FileManager instance, useful for locating files. ```javascript baseURL basePath ``` -------------------------------- ### Show Command Palette Source: https://docs.getdrafts.com/docs/automation/shortcuts-reference Show the command palette. ```APIDOC ## Show Command Palette ### Description Show Command Palette. ``` -------------------------------- ### Wiki-Style Link to Workspace Source: https://docs.getdrafts.com/docs//drafts/cross-linking Create a link that opens a specific workspace within Drafts. This is useful for quickly switching to predefined workspace configurations. ```markdown [[w:Workspace Name]] ``` -------------------------------- ### JavaScript FileManager Date Functions Source: https://docs.getdrafts.com/changelog/changelog-mac New functions are available on the `FileManager` object to get and set the creation and modification dates of files. ```javascript FileManager.getCreationDate(path) ``` ```javascript FileManager.getModificationDate(path) ``` ```javascript FileManager.setCreationDate(path, date) ``` ```javascript FileManager.setModificationDate(path, date) ``` -------------------------------- ### /create Source: https://docs.getdrafts.com/docs/automation/urlschemes Creates a new draft with specified content, tags, and folder. Optionally runs an action on the new draft and can return the draft's UUID. ```APIDOC ## CREATE ### Description Creates a new draft with the content passed in the “text” argument. If an x-success url is provided, it will be called with the `uuid` parameter indicating the UUID of the draft which was created. ### Method `drafts://x-callback-url/create` ### Parameters #### Query Parameters - **text** (string) - Required - Text to be used at the content of the new draft. - **tag** (string) - Optional - Name of a tag to attach to the draft. This parameter can appear multiple times to add more than one tag. - **folder** (string) - Optional - Location for the new draft. Accepted values: `inbox`, `archive`. Default: `inbox`. - **flagged** (boolean) - Optional - Should the newly created draft be flagged. Default: `false`. - **action** (string) - Optional - Name of an action in the action list. If provided, this action will be run on the specified draft. - **allowEmpty** (boolean) - Optional - If an `action` parameter is provided, adding `allowEmpty=false` to the URL will prevent that action from running if the text is empty. This can be used to terminate a loop of x-callback-urls running on lines of a draft. - **retParam** (string) - Optional - The name of the argument to use to pass the draft UUID back to the x-success URL. Defaults to “uuid”, but if the requesting app expects another value (like Workflow’s “input”) use this argument to override. ### Request Example ``` drafts://x-callback-url/create?text=Hello%20World ``` ### Response #### Success Response (x-success) - **uuid** (string) - The UUID of the newly created draft. ``` -------------------------------- ### Get Current Draft in AppleScript Source: https://docs.getdrafts.com/changelog Retrieve the current draft in the editor using AppleScript. This command now handles cases where there is a new blank draft. ```applescript get current draft ``` -------------------------------- ### Prompt for Draft Creation with allowCreate=true URL Parameter Source: https://docs.getdrafts.com/changelog/changelog-mac Using the `/open` URL with `allowCreate=true` will now prompt before creating a new draft. This affects wiki-links and prevents unintentional draft creation from mistyped links. ```url /open?title=NewDraft&allowCreate=true ``` -------------------------------- ### Quick Capture Source: https://docs.getdrafts.com/docs/automation/shortcuts-reference Show quick capture interface. ```APIDOC ## Quick Capture ### Description Show quick capture. ``` -------------------------------- ### Get Draft Location Information in AppleScript Source: https://docs.getdrafts.com/changelog Retrieve creation and modification location data for a draft using AppleScript. This feature is available on Mac. ```applescript creation location ``` ```applescript modification location ``` -------------------------------- ### Get All Calendars on Device Source: https://docs.getdrafts.com/changelog/changelog-ios Retrieve an array of all calendars known to the device using `Calendar.getAllCalendars()`. This provides a comprehensive list of available calendars for scripting interactions. ```javascript const allCalendars = Calendar.getAllCalendars(); allCalendars.forEach(calendar => { console.log(calendar.title); }); ``` -------------------------------- ### Show Quick Search Source: https://docs.getdrafts.com/docs/automation/shortcuts-reference Show the quick search interface. ```APIDOC ## Show Quick Search ### Description Show Quick Search. ``` -------------------------------- ### Get Current Draft Properties with AppleScript Source: https://docs.getdrafts.com/docs/automation/applescript.html This AppleScript snippet shows how to access the currently active draft in the Drafts editor and retrieve its content and tags. ```applescript tell application "Drafts" set myDraft to current draft set myContent to content of myDraft set myTags to tag list of myDraft end tell ``` -------------------------------- ### Get Recent Tags with Tag Script Object Source: https://docs.getdrafts.com/changelog Retrieve a list of recently used tags using the Tag script object. This replaces the deprecated Draft.recentTags(). ```javascript Tag.recentTags() -> [string] ``` -------------------------------- ### Escape Template Tags Source: https://docs.getdrafts.com/changelog/changelog-ios To prevent template tags from being processed, you can now escape them with a backslash. For example, `\[[title]]` will be displayed as `[[title]]` instead of inserting the draft's title. ```text \[[title]] ``` -------------------------------- ### Open Scratchpad with Text via URL Scheme Source: https://docs.getdrafts.com/docs/misc/interact-scratchpad Use the 'interact' URL scheme to open the Scratchpad and parse plain text into contact data. The 'text' argument should be URL encoded. ```url interact://x-callback-url/scratchpad?text=Hello%20World ``` -------------------------------- ### Markdown Format Bookmarklet Example Source: https://docs.getdrafts.com/docs/extensions/web-capture This bookmarklet captures the current page's title, URL, and selected text in Markdown format. Drag this to your bookmarks to use. ```javascript javascript:(function(){var d=document;var t=d.title;var u=d.location.href;var s=d.getSelection();var url='https://capture.getdrafts.com/?text='+encodeURIComponent('[%20'+t+'%20]('+u+')%0A%0A%3E%20'+s);window.open(url,'_blank');})(); ```