Can’t append text to existing drafts using the Add to Draft action in the Shortcuts app

Hello, I’m having trouble appending text to an existing draft using the Add to Draft Action in the Shortcuts app. I’m not sure if I’m doing something wrong or is it caused by Drafts/Shortcuts. Please help me solve this problem, thank you in advance!

To reproduce the issue, please do the following steps:

  1. Create a shortcut in the Shortcuts app that contains two actions: Text and Add to Draft. The Text action contains the text to be appended to an existing draft, and the Add to Draft action is to be configured as follows:
  • Mode: Append
  • Draft UUID: Fill in the UUID of the draft you want the text to append to
  • Edit in Drafts: No
  • Run Action: No

This is an example I made.

  1. Create a Drafts Action that contains only a single Run Shortcut Step. Fill in the name of the above shortcut. Configure the Action as follows:
  • Wait for Response: Yes

This is an example I made.

Now, trigger the Drafts Action. The Action should launch the shortcut which appends some text to an existing draft. My problem is, I can see the text being appended to the draft when Shortcuts launches Drafts for the first time, but when Shortcuts launches Drafts for the second time, the appended text disappears. I tried multiple times and the always got the same result.

Can I check whether the shortcut works if you just run it from the Shortcuts app?

Is there a specific reason why you need to trigger the shortcut from Drafts and have it update a Draft?

I’m asking because I’m wondering if the jumping out of Drafts to Shortcuts and back in is causing the problem. If it is, then understanding why you are jumping out and back to Drafts might allow me to suggest an alternative approach.

It does seem a little strange to do it this way rather than say pass back some data to Drafts from Shortcuts and have Drafts process it, but this approach works in my quick testing.

Hope that helps.

Hi, thank you for your reply!

I just ran a quick test and if I trigger the shortcut within the Shortcuts app, the appended text does not disappear when I return to Drafts after running this shortcut.

There is a reason why I want to trigger this shortcut within an Drafts Action. What I actually want to achieve is more complex than simply triggering an Action which runs a shortcut, but to make my question simpler, I didn’t mention the unrelated parts of the shortcut and draft action. If you’re interested, here is the full version of what I have built:

  1. Take a picture with the Camera app
  2. Launch Drafts and write some text related to the picture just taken
  3. Trigger a Drafts Action containing three Steps:
    1. Script: Run a script to add some predefined tags to this draft
    2. Run Shortcut: Run a shortcut in the Shortcuts app. This shortcut performs the following actions:
      1. Create an image in DEVONthink To Go
      2. Get the item link of this image and append it to the previous draft
    3. URL: Create a new task within my task manager app. The title of the task is [[title]], the content of the task is [[body]] and the tags of the task is [[tags]].

With the help of the shortcut and Drafts Action described above, I can take a picture related to a task, write some description in Drafts, trigger the Drafts Action and then I’m good to go. When I launch my task manager app, I have a new task with [[title]] as its title and [[body]] as its content. The [[body]] also contains a DEVONthink item link at its end and when I click the item link within the task, I will be instantly brought to the picture I took.
The problem is, because the item link appended to the draft with Add to Draft always disappears, the task in my task manager app does not have the DEVONthink item link at its end. I figured out the missing item link was caused by the Add to Draft action, so I created a super short version of the shortcut and Drafts Action I created to describe my problem.

Hi, thank you for your reply! I do realize the shortcut and Drafts Action I gave as examples in my original post seemed rather unnecessary. This is because the shortcut and Drafts Action I posted were only short versions of what I was actually trying to create. I figured out the problem was caused by the Add to Draft action in Shortcuts, so I thought I’d make my question simpler by only mentioning the related parts. Please see the full version of what I was trying to create in my other reply in this post if you’re interested.
I am quite new to Drafts and did not realize there was a Insert Text Step in Drafts, and I solved my problem by replacing the Add to Draft action in Shortcuts with the Insert Text Action Step in Drafts. Thank you for your help! However, I still do not understand why the appended text disappears when I try to append text using the Add to Draft action in Shortcuts. Could you please provide some insight on this issue? Thanks again!

It works for me if I get your test action to include the UUID in the template and call my test shortcut, which is very similar to yours except for the generic utilisation of the UUID.

Therefore that suggests your issue is in the specification of the UUID in Shortcuts.

Are you 100% sure your UUID for the draft in Drafts always matches the UUID specified in your Shortcuts custom shortcut? I suspect it is updating a different draft which would be one reason you might briefly see the text added to a draft and then seemingly not present when it returns to (a different draft) at the end of the shortcut.

In fact, I did include the UUID of the draft in the template so as to pass the UUID of the draft I’m currently editing as the shortcut input into my shortcut, so I’m sure that the text was appended to the right draft. Also, during my previous tests, before triggering the Drafts Action, the draft contained

Test
This is a test

Then I triggered the action, which ran the shortcut. I could see the previous draft became

Test
This is a test
Appended text

before Drafts launches Shortcuts again. Then Shortcuts launches Drafts for the second time, and the draft became

Test
This is a test

again. I have absolutely no idea what I was doing wrong.

Thank you so much for helping!

Thanks, that makes it much clearer.

I’m still unsure as to why the issue is occurring. I will try to take a look when I finish work today.

Dave

I have no idea why this is happening either. Thank you so much for your help!

I’ve just tried this with your example Shortcut and Draftsaction and, unless I’m missing something, it looks like its working:

https://share.icloud.com/photos/0gD3e9_HDRffTSoQeyA05zd0A

Dave

Thank you so much for testing the shortcut and Drafts Action! However, the issue still persists when I try, please take a look at this Screen Recording.
I’m starting to feel that I must have made a really stupid mistake somewhere. Please tell me what I’m doing wrong, this issue is bothering me a lot. Thank you again!

I’m afraid that I don’t know what’s going on there. It’s not clear why it would behave differently for you

I’m completely at lost too. I might consider contacting the developer for further insight.
Thank you so much for your kind help!

This is not exactly a bug…though it certainly is an issue. The problem results from attempting to manipulate the draft that is the draft in context of the current action from outside the context of that action and creating a race condition about what is the correct content of the draft.

It hasn’t come up before, but I should likely add a hard lock on the current draft while the action is running and throw an error if Shortcuts or another source attempts to manipulate that draft via URLs while it’s in context.

This would work fine if the draft Shortcut is targeting is not the same draft that was in context when the action was run.

If your Run Shortcut step is not set to wait for a response, this works, also. The action completes before Shortcuts attempts to make changes to the draft - at least in my testing I can’t get it to fail if wait for response is off.

If it is on, Drafts is waiting for Shortcuts to finish. Your shortcut comes in an edits the draft via URL while the action is still running - but the action is not aware of these changes and it is operating on the draft as it existed prior to those changes being made. Which is how it should be, because other steps/scripts in the action could have made changes to the content of the draft as well and those should not be discarded.

Not sure what your ultimate goal is here, if you describe your task I could suggest other ways to accomplish the result.

There are plenty of ways to avoid this problem, if you describe what you are trying to accomplish. If you are trying to insert content generated from Shortcuts in the current draft, it would be better to have the Shortcut return the new text to Drafts and have Drafts update the current draft.

Hello, thank you for your explanation! I explained in one of my replies to another user what I am trying to accomplish. The Drafts Action and Shortcuts shortcut I gave as examples in my original post didn’t make any sense because I was trying to make my question simple and clear so I removed the steps unrelated to this issue.
Coincidentally, I saw your TIP post several days ago about inserting the result of a shortcut in current draft, which provided a perfect solution to my problem. The [[shortcut_result]] tag is extremely useful and powerful, thank you so much for your tip!