These calls are cumulative over the course of the script key script's execution, and only the final values will be applied to the edited text on successful completion of the script.
Examples of things that can be done with scripts keys include regular expression search and replace of text, insertion of common formatting elements such as Markdown or HTML tags, upper or lower casing text selections – and much more.
- getText() : Returns the full text currently being edited.
- setText(string) : Replaces full text being edited with string.
- getSelectedText() : Return only the selected text. If no text selection exists, this will return an empty string.
- setSelectedText(string) : Replace only the current selected text range with the string. Also updates the selected range to match any change in length of the new string.
- getTextInRange(start, length) : Return text in the request range.
- setTextInRange(start, length, string) : Replace the text in the specified range with the value of string.
- getSelectedLineRange() : Returns the range (start,length) of the full line based on the current cursor position
- getSelectedRange() : Returns the current selected text range as an array with values [start, length].
- setSelectedRange(start, length) : Set the selected range of text. Invalid ranges will be automatically adjusted, and this text selection will be applied after successful completion of the script.
- getClipboard(): Returns current contents of the system clipboard.
- setClipboard(string): Set the system clipboard to the string passed.
- markdown(string, useXHTML) : runs the string through the Markdown processor returning HTML.
- encodeHTMLEntities(string) : Encodes the string to HTML safe entities, e.g. converting & to &
- decodeHTMLEntities(string) : Decodes HTML entities.
The best way to get started with scripting keyboard extensions in Drafts, is to look at some examples. And the best place to find example is in the Drafts Action Directory.