The online home of John Pollard

Using NFC and Launch Center Pro to launch Spotify

Probably saves me a couple of seconds every day :)

I’ve been thinking about playing about with NFC tags for a while, and when Launch Center Pro released a new version that both supported NFC and lets you buy a sticker pack, I thought it was a good time to jump in.

When I’m coding, I’ve got an almost Pavlovian need to have music playing. I think after spending years working in open-plan offices wearing headphones to isolate myself from distractions, I can’t actually work without music on anymore.

Now I spend most of the time working at home, I still have music on - and I’m a long time Spotify subscriber (the quality of their recommendations are unsurpassed!)

Writing a Siri Shortcut to start Spotify playing

Note this section was updated from the original post, as the simple way of just opening the URL spotify-action://press-play stopped working just after I originally wrote this 😠

The shortcut to resume Spotify playing basically uses the Spotify Web API to control playing in the app.

This API is still in Beta, so hopefully won’t change/break in the future, but in essence the shortcut does the following:

  1. Fetches an access token from https://accounts.spotify.com/api/token using a client ID and secret you’ve setup on the Spotify developer dashboard
  2. Open the Spotify app - you need to do this first because of an existing bug in the Spotify API
  3. Call https://api.spotify.com/v1/me/player/play?device_id=[Device ID] to resume playing, using a device ID you’ve found by previously calling the devices API at https://api.spotify.com/v1/me/player/devices

If anyone is interested, let me know and I’ll make the effort to make my script more reusable and shareable, as at present I’ve hard-coded the various IDs into my shortcut 😱

Setting up an NFC Trigger in Launch Center Pro

The LCP NFC integration is really nice. To add a new sticker, you just press “+” in the ‘NFC Triggers” section of “Settings”, and it lets you scan one of your tags and give it a logical name.

Then it’s simple to associate an LCP action with that trigger - obviously here I setup an action to run my Shortcut e.g. shortcuts://run-shortcut?name={{Play Spotify}} where “Play Spotify” is the name of the Shortcut.

Running the Shortcut

To run the Shortcut using the tag, I just move my iPhone XS Max over the NFC tag, which triggers a notification asking if I want to “Open in Launch”.

Tapping the notification then opens the LCP action, and after a couple of seconds Spotify starts playing.

It would be much nicer if I didn’t have to tap the notification to kick things off, and if you’re not shown all scripts running in LCP and Shortcuts.

The notification restriction is down to Apple’s security rules - so not sure we’ll ever get rid of that - but hopefully at some point soon Apple will better integrate Shortcuts so we don’t have to see the app running in the foreground. iOS13?

If none of that made much sense, here’s it all in action …

Other NFC ideas …

I’ve added a tag to the dashboard of my car, and written a Shortcut that can do one of “Play Spotify”, “Play Overcast” or “Open Google Maps with directions home” - the 3 possible things I usually do when I get in the car.

My next idea is to start and stop Toggl timers from another tag on my desk, but I’m waiting for the almost mythical forthcoming Timery app before I do, as I can’t face tackling the Toggl API myself.