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.
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.