Shortcuts, Twitter, and Random Drafts

The Goal

I want to fire a shortcut that does the following:

  1. Selects a random draft with tag_a
  2. Tweets the content of the draft
  3. Prepends the draft with text
  4. Removes tag_a
  5. 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 :call_me_hand:t2::palm_tree::hibiscus:

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"

// get all drafts with pendingTag
let drafts = Draft.query("", "all", [pendingTag])
if (drafts.length == 0) { // didn't find any
	alert("No matching drafts found")
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")
	else { // tweet succeeded!