TIP: Working with existing drafts

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.


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.

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.

1 Like

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.

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.

Would it be possible to help me figuring out an action to insert a draft with a specific title (or tag) directly without having to scroll through the drafts ?

Thank you

Yes, but you would be better posting this as a new topic as your question is not really discussing the original topic.

Clarify your question with how you determine the draft to insert into, where in the draft you want to insert and the what to insert - I couldn’t tell if you were inserting the content of another draft into a current draft or some content into another draft. A worked example/steps of what you want to do can be helpful for this.

Note also tags and titles are separate, would you want to be able to search by both together?

Thank you very much -will do !