Selecting a draft by name/title in Shortcuts

When I use the Shortcut action “Update Draft” and use the text of the title of the draft as the draft I wanted updated, instead of acting on the draft with that title, Drafts returns a list of all drafts containing the text, even though there is a draft with the specific text as its title.

This comes up in the following use case: I have a set of drafts that I use as running logs on various projects. They have a label “log.” When activated (via a drafts action or on its own) my shortcut searches drafts based on that tag, and then asks me to Choose From that list for the log draft I want to update. Later in the shortcut, Update Draft acts on the draft I selected. If I use the Draft variable in Choose From, it works fine, but the selection window shows the draft title and the first lines of the drafts, which is unwieldy. If I use the “Title” or “Name” variables in Choose From, it shows a cleaner list of just the titles. However, the output from that step is only text, and when I use that text in Update Draft, the problem of the search occurs.

This seems like unexpected and not optimal behavior. When the action “Update Draft” receives a text string, and there is a draft with that text string as its title, shouldn’t we expect Update Draft to operate on that draft? Is there any way to make it do this?

“Update Draft” takes a draft object. You have to be specifying an actual draft and that should work that way.

If you want to build a custom selection option, your best bet is probably to load the drafts, do your selection with the title, then use some kind of process to select the draft with the matching title from the list of drafts and pass it to Update Draft.

I don’t use Shortcuts for much, so I’m not sure what the best mechanics for that would be…I assume you could do some Repeat over the list of drafts and compare if the title matches the string returned from your selection, and then set a variable or something to hold the matching draft and then pass that variable to Update Draft?

Yes, I think that’s doable in Shortcuts and the necessary solution. I was hoping perhaps there was some way to get Update Draft to work off the title. It does if the text of the title doesn’t appear in any other drafts. So I guess more of an undocumented feature - if you pass text to Update Drafts (or any of the draft selection shortcut actions) it will search for that text and offer you a choice of all responsive drafts.

You can do something like this: Shortcuts

To help you further on your own shortcut it would be helpful if you share it so we / I don’t have to rebuild it from your description :wink:

Thank you - not looking for help building my Shortcut, just want to get clarity on how the Drafts Shortcut Actions work. Not sure I’ll take the time to implement (selecting from a list of drafts vs a list of titles isn’t the end of the world) but the way I’d do it would be to search on the title text, then if there’s more than one hit, evaluate each responsive draft by checking if the title matches the search text, and returning the draft object for the one that matches, which I think is what agiletortoise was proposing.

Looking at your request the only thing that I would see as a feature request would be querying Drafts by title (if you now use the Search Drafts step it will search through the hole content OR have an shortcut action that lets you Update a Draft by title.

For me the Update Draft step does exactly what I would expect (update a given draft) but I have a Software development background so might not be the best to judge this :blush:

What I intended with my example is that you could built this into your own shortcut to get this working with your existing shortcut :blush:

Just to note you can tell a search action in Shortcuts to only match against draft titles using the standard Drafts query options.

So you could have something like the excerpt shown below, but feeding your chosen text in prefixed with title: for the search input, limited to 1 result, and then the draft result out of that would be passed to your update action as you describe in your original post.

Hope that helps.

1 Like

Brilliant, worked perfectly. Interestingly, the “title:” syntax doesn’t seem to affect “Update Drafts” that still returns all drafts with the text anywhere in the draft, but adding the “Search Drafts” step is easy enough and does the trick. Thanks!

Could you share and example shortcut that explains what you saying about Update Draft? That doesn’t make sense to me, because Shortcut should not allow you to pass a string to that action.

Sure, here you go.

https://www.icloud.com/shortcuts/6026fca2056c411193a114420230ad1b