Controlling a Mac with Amazon Echo or Google Home

Asking Google Home or Amazon Echo to play any song you like from the Spotify catalog is extremely liberating—but until there is support for the Spotify Connect feature, these devices can only play back music on their own speakers, or on speakers to which they’re directly connected. I have AirPlay speakers all over the house and I would like to be able to tell Alexa or Google Assistant to play a given song in my living room or my kitchen or in my office—or any combination of those locations—but that’s just not possible today. This was the biggest of the complaints I wrote about last week in my comparison of Echo and Home.

Persistence and hackery can overcome almost any tech roadblock though. Over the weekend I strung together a series of tools that allow me to issue voice commands to Google Home (which I prefer slightly) to select music on Spotify, then switch the playback to the Mac mini that sits at the heart of my home theater setup, and from there pipe music to the various AirPlay speakers in the house.

What’s more interesting is that the basics of this solution could theoretically allow you to control almost anything on your Mac via voice—and it’s incredibly easy to set up. It starts with the invaluable IFTTT service, which supports both Google Assistant and Alexa. You can define your own custom phrases to serve as IFTTT triggers, which can then generate simple text files on a cloud storage service like Dropbox, which can kick off automated routines on your Mac. This is what it looks like to set up the IFTTT component:

IFTTT Configuration

When you set Dropbox to sync the resulting text files to your Mac’s hard drive, the key is to do so to directories that you’ve loaded with macOS’s Folder Actions feature. Basically, when the text files are added to these folders, they act as triggers for Automator actions, which can do tons of stuff, including run AppleScript code—which in turn can do even more stuff. Once Automator is done, it can even clean up after itself by trashing the text file it used as a trigger, if you need.

Automator Folder Action

This is the basic approach I use to enable Google Home to play music throughout my house, though there are more steps involved, and some janky workarounds. Using the Home’s built-in voice commands I search for and play the songs I want, just as you would normally do. Then I speak a custom phrase like “Switch tunes to home theater” (most music playback-related phrases are reserved by Google Home so you can’t just say “Ok Google, play music on my home theater”) to kick off an IFTTT applet. The applet saves a text file in Dropbox, which syncs to my Mac to a directory with a folder action attached to it. That action runs a bit of AppleScript to open Spotify and, through the brute force of repeating pre-recorded mouse locations and clicks (courtesy of an extremely unsexy app called Mac Auto Mouse Click), it opens the Spotify Connect menu and switches the playback device from Google Home to the Mac mini. Then finally (whew), Automator also tells AirFoil to redirect that music to a pre-defined set of AirPlay speakers. All of a sudden, the music I asked for in the kitchen is playing all over the house.

Granted, the setup is hardly elegant, to say the least. The beauty of it is that it’s incredibly simple to set up, easy enough that I’ve created a series of similar commands to play and pause the music, jump back and forward, etc. As I’ve said in the past, I’m not a programmer by any means—before this weekend I had never spent more than a few minutes in Automator or writing AppleScript—so the learning curve is shallow.

This kind of rudimentary but highly engaging automation is sure to become more and more central to consumers as voice-powered interfaces gain ground. So it’s all the more concerning that Apple parted ways with its longtime champion of automation products last fall, though perhaps there are other plans afoot to continuing evolving the automation of Apple’s devices and software. Looking ahead at a future filled with these kinds of devices, as users we are only going to want the apps and services that we use to be more scriptable, more responsive to integrations. And we’ll want that ability to automate to be simple enough that we can put together the missing flows and actions that we want ourselves.