Drafts 4 Keyboard Scripts
Drafts 4 supports standard JS but includes a few extra functions for working with the text window. Here’s the list from the Drafts help:
- 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
- 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.
This is where the fun begins.
I wouldn’t classify myself as O.C.D. I like to think I’m more pedantic that anything else. When it comes to lists, sometimes it really bothers me when they’re not in sort order. This is especially true of Markdown lists that are only keyed off the first list item.
Here’s a keyboard script that scratches my lizard brain just right. It takes a list like this:
:::text 5. Cat Food 3. Binoculars 2. Pebble to suck on 1. Lefty scissors
and converts it into a list like this:
:::text 1. Lefty scissors 2. Pebble to suck on 3. Binoculars 5. Cat Food
To add this to the extra keyboard row in Drafts 4, do this:
- Click the pencil icon on the extra keyboard row to edit the keys
- Add a new key with the plus in the upper right corner
- Choose a “Script” type key
Here’s the script1:
Speaking of pedantic, I like my timestamps and I like them in a specific format. When I create notes, I regularly insert timestamps at the beginning and in-between notes. This keyboard script makes it easy:
I use this all the time and it’s terrific.
Flexible, Light and Powerful
Those are the three reasons I keep returning to Drafts for basic notes. It’s the jumping off point for words. I don’t sit and write in Drafts, but I could. I don’t archive all of my notes in Drafts, but I could. What I do, is launch Drafts and write about a hundred times a day. I use Drafts because it’s a world of options.
Drafts for iOS | Universal | $5