Damola's blog

It's time to take iOS shortcuts seriously.

iOS shortcuts are getting more powerful. I built one for Shazam to open Spotify.

January 03, 2021 | 3 min. read

I recently wanted to Shazam a song and have it open in Spotify (the one true music streaming service) on my iPhone - but Siri and control center only allow Apple Music. It can only be done by downloading the Shazam app, configuring it to use Spotify, and then opening the app every time to find a song - for it to go to Spotify. This mildly annoyed me because I know how easy it is to do this on Android. So I went out on a hunt for the easiest way to do this - Shortcuts 1.

It turns out iOS has way more Shortcut actions than I remember - including one for Shazam. I tried to find a pre-made Shazam shortcut that opens Spotify but only found a very bloated and rather convoluted one - Shazam++. So I decided to just build one myself. Iā€™ve built shortcuts before and already know how the work.

The flow is fairly simple:

  • Call the Shazam action which does its magic, identifies a song and returns the result.
  • Use the result to open Spotify. Unfortunately, the result (from Shazam) returned is so tied to

Apple ecosystem that itā€™s not possible to open Spotify directly from it (all the links and track info are Apple Music specific). So I had to find a way to get the Spotify link to the song given its Apple Music info. Luckily, there is a free API: Songlink, that does literally that. I found out about the API while digging through the Shazam++ shortcut code:

  • Parse the json response (using the Get dictionary from <> action) from the song link api to get the Spotify link.
  • Open Spotify
  • ???
  • Profit.

What blew my mind here is finding out that Shortcuts on iOS can make arbitrary HTTP requests and parse the response (json and xml) into a key value dictionary that can be used later in any other action. Thatā€™s the core logic of a lot of ā€œrealā€ applications. All without writing a line of code.

This made me very excited for all the wild things I could experiment with. So I also made a shortcut that lets me change the iOS wallpaper without downloading the image into my photo gallery. Which has been a very annoying quirk with iOS for a very long time. This was legitimately one of my major qualms with iOS vs Android. I now have way to change it seamlessly. Whatā€™s more, iOS also has ā€œAutomationā€ - so you can have actions run without any user action. I now have an automation to change my wallpaper on a schedule - transparently. I donā€™t even think iOS apps have this capability yet - so this is kind of a way to do more than a ā€œregularā€ app could, mind blowing.

I have the screenshot of the automation below and the equivalent shortcut that is run below.

A daily automation to run a shortcut.
A daily automation to run a shortcut.

A shortcut to download a random image from Unsplash and set it as wallpaper.
A shortcut to download a random image from Unsplash and set it as wallpaper.

The shortcut above is possibly one of the basic, out-of-reach capabilities Iā€™ve been wanting/wasnā€™t aware of:

  • get data from an endpoint
  • perform an action on the data
  • all without user input.

I canā€™t share an automation, but I can share shortcuts, the iCloud link to the Shazam+ (thatā€™s the name I settled for) shortcut is here. If youā€™d like to see the logic before downloading, hereā€™s a screenshot.

The wallpaper (images downloaded from Unsplash) shortcut is here;

And thereā€™s a more ā€œinteractiveā€ one here that allows cycling through images before setting a preferred one.

These can be used as-is but are easy to customize, theyā€™re intentionally kept simple. Go forth and automate! šŸ¦øšŸ¾

Iā€™m definitely going to be making using Shortcuts more.

This totally qualifies me as an iOS engineer, no?


References

[1] ā€œA shortcut is a quick way to get one or more tasks done with your appsā€. Read the official Apple docs.


Adedamola Shomoye

By Adedamola Shomoye

Join the...