TIP: Working with existing drafts


#1

Drafts provides a handy script method to select an existing draft, which prompts you with a draft browser and returns the draft selected. Using this method makes it easy to work with existing drafts.

A couple of quick, ready-to-use example actions which take advantage of this method:

  • Append to Draft: Prompts to select a draft, and appends the content of the current draft to that draft - then archiving the draft. Useful when typing a quick note you later want added to a longer draft you had in-progress. Works much like capturing with the Drafts’ Share extension from another app.
  • Insert Draft at Cursor: Prompts to select a draft, and inserts the content of the selected draft in the current draft at the cursor. Great for using other drafts a re-usable snippets.

In your own scripts, the method is app.selectDraft(), and is used as follows:

let d = app.selectDraft();

After that line, the d variable contains a Draft object, and any of the content and other properties of the object can be used.


#2

Looks good. Just now I thought of a case where I want to run a Shortcuts cut and append the text to either an existing draft or into a new draft.

Does this draft selector allow you to create a new draft? Half the time I’d want to append to an existing draft and half the time I’d want to append to a new draft. Bonus points for the selector allowing Cmd+n to create a new draft.


#3

I dont know if this is supported, but at least you could just use a prompt and ask if you want to append to an existing draft or create a new one - based on the selection of the prompt (in an if-else condition) you can either use the selector or directly create a new draft.


#4

I actually coded that up - and changed the input to be not the current draft but the contents of the clipboard. So I now append to the end of an existing draft or create a new one.

So my experience is that the two-step process of cancelling out of the selection dialog and then having to say whether I wanted to create a new draft or not use the text felt cumbersome.

A “new draft” button would be slicker. But not essential, obviously.


#5

I notice that Drafts remembers the state of the tag filter, even when the action is cancelled, but not the choice of folder. Also that the current workspace is ignored entirely. For my money, it would be useful to have the workspace recognised too, but nevertheless, it’s another good feature.