An Apple Shortcuts shortcut to use with Drafts to make omg.lol pURLs from selected text πŸ”—πŸ§‘πŸ»β€πŸ”¬πŸ§ͺπŸ”₯

Β· 600 words Β· 3 minute read

I made a thing.

I was posting a link to Mastodon this morning and went just over the 500-character limit, so I went over to omg.lol’s pURL service to get a short link and I thought about how often I fumble around trying to find where to go make those, so I made a shortcut:

https://mph.url.lol/omg-purl-shortcut

πŸŽ“ I’ve never done a Shortcut that talks to an API before, so that was educational.

It is not meant to be used on its own, but you can edit the first and last steps to do that and plumb it into whatever. I made it for my use case, which is as a Drafts action that works on the selected text and replaces it with a shortened URL.

Not sure what the etiquette is for posting Drafts actions, and this one is so plug stupid I’m not sure if it’d survive curation, so here’s the transcript of creating the action:

Step 1: Run Shortcut pURL Shortener, input [[selection]]

  • βœ… Return to Drafts
  • βœ… Wait for Response

Step 2: Insert text, Template [[clipboard]]

That’s it.

πŸ“• So the workflow is just you’re typing along and think “I need to shorten this link” so you select the link and fire the action, the Shortcut asks you for a name (it doesn’t sanity check this at all) and the selection gets replaced with the new pURL. Huzzah.

πŸ’‘The shared Shortcuts link should ask you for your omg.lol API key, which you can find toward the bottom of your account page. If it doesn’t for whatever reason, just open the shortcut and fill in the Text step right underneath the comment that begins “Your API key goes here.”

⚠️ It is not a genius. It does know if it gets something other than a 200 response. I could have just used Success instead of the response code, but I wanted to leave open the option of offering a more useful error message. If it doesn’t get a 200 back it assumes the worst and pops up an alert telling you something went wrong. You’ll know that, though, because your selected text will have been overwritten with something you were not expecting at all.

⚠️ It overwrites your clipboard, too. I don’t care because I use Alfred’s clipboard history, but lord knows what some people expect to be in their clipboard 24 hours later. Nuclear codes. Number they got at a bar. I don’t know. I worked IT for years: You either embrace Calvinism or become a Buddhist.

⚠️ It destroys the current selection in Drafts so … select wisely? And see the previous caution?

Things to do with this πŸ”—

  • Make a version that works as a generic shortcut for use with RSS readers, etc, copying the link to the clipboard.
  • Make a version that responds to something like https://some.url.com|shortcut_name when sending from Drafts, so you don’t have to enter a name into an alert.

Things I learned πŸ”—

  • If you’re dealing with nested values in a response, you use dot notation. So to get status_code out of this response:

"request": { "status_code": 200, "success": true },

You want to use a Get dictionary values step from the URL contents response, then a Get Value step that reads request.status_code.

  • The if statement in Shortcuts is input sensitive. So if you put it after a get contents of URL action, the thing it checks for is whether there was a response at all. If you want it to compare values (e.g. to check a response code) you have to add a Get numbers from your Get Value step.