By Jason Snell
January 4, 2018 3:49 PM PT
Remote control a Mac from an iPhone via Workflow
Warning: This story has not been updated in several years and may contain out-of-date information.
Handoff is a nice feature that I use here and there to transfer data between my Mac and iOS devices, but it’s the exception that proves the rule: It’s not particularly easy to control a Mac commands from an iOS device. (It’s also frustratingly hard for my Mac to communicate with my iPhone about an event back at my desk.)
Yes, if I absolutely need to control my iMac Pro from my iPhone, I can launch a screen-sharing app (I use Edovia’s Screens), but pushing a cursor around a 27-inch iMac from an iPhone screen is ridiculous. What if you just want to pause iTunes on your Mac, or turn down the system volume, or send it a webpage from across town, or anything else you can think of?
Dan Sturm, co-host of the Defocused podcast, was frustrated about a lack of Mac remote control, too, and he decided to solve it. His solution is unusual and will undoubtedly make security-minded people aghast, but I’ve tried it and it really works—though I’ve modified it to make it a bit less terrifying, security-wise. (I should point out that there’s a less technical solution here, which is to use the Mac app Alfred and the Alfred Remote iOS app, though I believe it only works when both devices are on the same network.)
Here are the steps:
Create a folder in Dropbox.
I called mine
Remote Scripts. Boring, I know.
Create an iOS workflow using the Workflow app.
Workflow is the tool we’ll use to trigger remote events on the Mac. You can have as many of these as you want, since each workflow can trigger a different event. I’ll show two examples, one of which is implemented as a share extension (so you can share a URL), the other of which runs from the Workflow widget in Notification Center.
For our first action, we’re going to create an Action Extension workflow that accepts URLs, gets the URL from the input, and writes a text file containing the URL itself to the special folder in Dropbox.
In the Save File block, you’ll need to authenticate with Dropbox and set the Destination Path to be the your folder in Dropbox, plus a filename starting with URL. I chose to append the Current Date (in RFC 2822 format) followed by the .txt extension, though that’s not strictly necessary.
Set up Hazel to process the files.
This approach uses Noodlesoft’s $32 Hazel Hazel utility, which can act on files and folders automatically when they appear on your Mac. In this case, Hazel will be processing a file added to the
Remote Scripts folder in Dropbox, so you’ll need to add that folder to Hazel’s Folders list and then make a new rule.
Here’s that rule:
As for the shell script itself, it’s a simple one that takes the URL in the text file, turns it into a variable called name, and uses the
open -e command to open it in the background.
file="$1" read -d $'x04' name < "$file" open -g $name
Once the script opens the URL, Hazel throws away the text file. That’s it.
Now if I’m on the Internet, I can browse to a webpage in Safari, tap the share icon, tap Run Workflow, and tap Open URL on Mac. A file will pop up in my Dropbox. Within a few seconds, the page opens in the background on my Mac, and the file disappears from my Dropbox.
Next task: Change Mac volume remotely
Dan’s next task was to figure out how to control his Mac’s volume remotely and quickly. Workflow allows you to create tappable buttons in the Workflow widget in Notification Center, which takes care of the “quickly” part. So how to set this up?
On the iPhone, I create a workflow that runs as a Today Widget called Mac volume. At the top of the workflow is a List item with five volume percentages: 0, 25, 50, 75, and 100. This is followed by a Choose from List item and then a Text item, which inserts the contents of the chosen item into a text file. As with the previous example, a Save File item saves the file to my special Dropbox folder—this time with the word Volume at the start of the filename.
In Hazel, I create a new rule that looks for Volume at the start of the filename and, like my other example, runs a shell script and moves the file to the trash.
In this case, the shell script is running a command to change my Mac’s volume to a specific percentage (which is filled in by the contents of the text file sent from my iPhone).
file="$1" read -d $'x04' name < "$file" osascript -e "set volume output volume $name —100%"
osascript -e command lets me issue AppleScript commands from within a shell script, which is extremely convenient in this case because the Mac’s system volume is accessible directly from AppleScript.
With this all in place, I can flip down the Today view in Notification Center, tap the Mac Volume widget, and adjust my Mac’s volume from my iPhone.
(Obligatory security note: If someone else has access to this folder of your Dropbox, they can probably wreak havoc on your Mac. You should be aware of that going in. Then again, if someone has access to your Dropbox, you may have other troubles, too.)
Use your imagination (and shell commands)
Once you’ve done a few of these, you can see how you could set up triggers for any number of Mac events, so long as you can figure out the specific shell commands to execute and embed the variables in a text file via Workflow. (Google searches will teach you much.)
This is one of the wackier bits of automation I’ve ever attempted on my Mac and my iPhone, but it really does work!
If you appreciate articles like this one, support us by becoming a Six Colors subscriber. Subscribers get access to an exclusive podcast, members-only stories, and a special community.