Using the x-callback-url with Shortcuts on iOS was great until... (it's been fixed!)

Development
//
October 8, 2020

I’ve been using Shortcuts on iOS for years now (even back when it was called Workflow) and it's always been a key part to keeping myself organized and productive in my every day life. With every iOS release, more actions get added and the overall experience and functionality keeps getting better. Especially when the ability to send and receive data from other apps using x-callback-url's was added, this really unlocked the power of Shortcuts and how it can connect apps that were otherwise in isolation, well, until now I guess.

With the latest iOS 14 release, there's been a bug with the "Open x-callback-url" action, where the Shortcut fails when returning any data back to the Shortcut. Currently this bug is present when trying to launch Shortcuts from the share sheet that have this action.

Previously on iOS 13, for example, I was able to send and receive data with Pythonista via the following steps:

  1. Append data via query parameters to the x-callback-url as you would a normal URL (the URL path is associated to the script you want to run)
  2. Run the "x-callback-url" action via the URL in Step 1
  3. Pythonista would then do its thing and send data back to Shortcuts (also via query parameters) to later be used in other Shortcut actions.*

*This unfortunately is where it fails; when returning back to the Shortcut, you end up going to the home screen instead and the Shortcut times out.

There are also instances of this bug occurring even when data isn't being sent back to the x-callback-url action in Shortcuts. If you have the Drafts app, you can check out this example u/Stokkes posted on r/shortcuts.

See it in action

If you have Pythonista installed on your iOS device, you can feel free to try this bug for yourself via the example below. There are other apps you can try this with (Drafts, Omnifocus or Scriptable for example, or even a plain URL will cause this to crash) but I am most familiar with Pythonista. See if the notification after the x-callback-url action will appear for you.

Replicating the bug on Pythonista

In this example, I'm sending the text "Hello World!" in Shortcuts via the query parameter to Pythonista, and having Pythonista send the data back to Shortcuts to display the text in a notification. Note, in order to experience the bug, you must launch this Shortcut from the share sheet.

The Shortcut

You can add this shortcut to your library to test. There are instructions in comment blocks throughout the shortcut to help with any configuration you may need to do.

Some key notes to make this Shortcut work with Pythonista:

  1. In the x-callback action, the value for the "Success Key" should be set to "argv" in order for the text passed to be properly read in Pythonista
  2. Make note of the file path of the Pythonista file. If you're storing it locally vs. iCloud, you will need to update the path in the URL action of the shortcut.

When you test, the shortcut is able to accept any input, so it doesn't matter what you choose so long as you launch the shortcut from the share sheet to experience the bug.

The Code

Paste this code in a file in Pythonista and save it in your iCloud folder. Be mindful of the iCloud path and that it matches your folder structure in iCloud.

So that's the bug. What now?

This only affects Shortcuts being opened from the share sheet. So if your workflow requires running directly from the Shortcuts app's home screen, then you're covered. But if you're like me and can only use Shortcuts from the Share Sheet, then you might have to look for an alternative. From my experience so far, trying to launch other Shortcuts after this bug occurs causes issues which sometimes requires me to restart my device.

Before this action was great for apps and services that don't have a public API but have enabled the ability for linking via the x-callback-url directly on the device. And I mean if you can't use it from the share sheet, it kinda undercuts the power of what a Shortcut can do. So, if you're solely relying on retrieving data from these apps locally on your device this bug unfortunately prevents you from doing that.

Since I'm not the type to wait on Apple for a fix, I've been trying to figure out a workaround by trying to use apps and services that have APIs instead. I use a lot these scripts to make a lot of my manual tasks easier; whether that's with project management, or scheduling social media posts of my photos or blogs.

This brings me to my next project that I am starting to work on, which is converting all of these scripts on my device to be hosted on a server side setup. I plan on making a REST API, built on Django and hosted on Heroku.

I've previously done a similar implementation using Node.js but since a lot of my logic and libraries I'm using are Python-specific, I figured Django would be the way to go, but this is the first time that I'm trying it out. Looking forward to sharing more about the shortcuts and scripts I use every day and hopefully making a more robust solution.

Thanks to u/Stokkes on Reddit for originally posting about this on r/shortcuts when iOS 14 was first released. The Drafts example I included above was used from their example originally posted in this thread on Reddit.

What about you? Do you use Shortcuts this way through your share sheet and have you seen this issue occurring on your devices?

Other Blogs