I’m having a problem with the shortcut “Run Action on Draft”–it basically seems to ignore the “on Draft” part and runs the action on either the current draft or, if the “New draft after” timer has run out, creates a new draft.
I have a draft called “Test”:
I have a shortcut that runs an action “Start” (which just inserts some formatted date text) on that draft:
But I end up with a new draft with the text in it:
It will seem to work if you have the draft you want to run the action on in focus in Drafts and the “New draft” timer hasn’t run out yet. I’ve tried more elaborate constructions where I first search for the Draft and then pass the results into the “on Draft” parameter via magic variable, etc. but nothing seems to work. Oh, except for doing it the old fashioned way with the old Shortcuts actions that use UUIDs, which works fine.
Can someone point out what I’m doing wrong?
Start action using an “Insert Text” action step? If so, this is expected behavior…even if a bit counter intuitive.
The reason being the “Insert Text” step interacts with the editor, not the draft, and the draft you are running the action on is not loaded in the editor when triggered in this manner. The same affect would be present if you use the
/runAction URL scheme…and would have similar outcomes if the action was scripted and used
editor functions to manipulated text in the editor instead of in the draft directly.
This is something I debating implementing these shortcut actions, but to avoid it would mean that running the shortcut would have to load the draft in the editor, ignoring whatever you currently had loaded. It’s possible that behavior makes sense now, when the shortcut action has to launch the app to operate, but if the shortcut action was able, in the future, to run in the background, there would not even be an editor to interact with.
You could force Drafts to load your draft and get the result you are expecting by scripting it in your action. Before the “Insert Text” action step you added a “Script” step with the following:
That would force Drafts to load that draft in the editor to be manipulated.
Yep, “Insert Text” is all the action is.
And I think I understand most of that…and in fact, I am now able to make it work! I had to go look up how to do a draft.query to select the right draft, but then it Just Works.
Thanks so much for the quick response, this is going to make keeping my time sheet considerably less annoying.*
(*I was using Toggl, but it behaves badly if it doesn’t have connectivity and there’s a dead zone just as you walk into my building…and as soon as that starts to work, I’m in the elevator, etc. Drafts is great for this as it doesn’t care whether it can talk to a server.)
For your application it might be a lot simpler and better just to use an
Update Draft shortcut action configured to append to the draft. It can run without Drafts ever opening.
My original idea was to have everything as Drafts Actions so I could do things within Drafts and then also be able to call them from Shortcuts via the widget view, but we’ll see. I’ve got something good enough to start using now, so I’ll see what I actually do with it and where the pain points are before going further.
Thanks so much for the tips!