The Goal
I want to fire a shortcut that does the following:
- Selects a random draft with tag_a
- Tweets the content of the draft
- Prepends the draft with text
- Removes tag_a
- Adds tag_b
——
I’m happy to share my existing approach, but I want to be sure the goal is understood before I overcomplicate things.
Mahalo
1 Like
Most of that is pretty straight-forward. The only gotcha I see is removing a tag via Shortcuts. Currently the update/file draft shortcuts actions can only add tags, which is a bit of a gap that I should address. Other than that, I’d say the shortcut should look like:
- Search Drafts, with tag filter “tag_a”.
- Get Item From List - selecting “Random Item”
- …tweet… (not sure how you are doing that, does Shortcuts have built-in Twitter?)
- Update Draft, Update Type: Prepend, Tag: “tag_b” (maybe also archive?)
As mentioned above, that would not remove “tag_a”, but otherwise does what you are suggesting.
You could, of course, do all that in a Drafts action as well, and run that action either from Drafts or Shortcuts - but it could not be run in the background.
For the record, a Drafts script to do what you describe would look like:
const pendingTag = "tag_a"
const processedTag = "tag_b"
const textToPrepend = "NOT SURE WHAT YOU ARE PREPENDING"
// get all drafts with pendingTag
let drafts = Draft.query("", "all", [pendingTag])
if (drafts.length == 0) { // didn't find any
alert("No matching drafts found")
context.fail()
}
else {
// select random draft from list
let d = drafts[Math.floor(Math.random() * drafts.length)]
// tweet it...
let twitter = Twitter.create()
if (!twitter.updateStatus(d.content)) { // tweet failed
console.log("Post to twitter failed")
context.fail()
}
else { // tweet succeeded!
d.prepend(textToPrepend)
d.removeTag(pendingTag)
d.addTag(processedTag)
d.update()
}
}
2 Likes