Menu

Making Siri Shortcuts run automatically – even when iOS doesn’t want you to

Favorites, Uncategorized Dec 03, 2019

I never seem to end up writing the blog posts I intend to.

This evening I wanted to followup on this morning’s release of VirtualHostX Pro and my reasons for switching to the new subscription model pricing structure I went with.

Instead, I’m burnt out from three weeks of pushing hard to get the app and the necessary server infrastructure out the door. So, that post can wait.

Let’s talk about something fun and related to my new obsession with Siri Shortcuts and CarPlay. Namely, how to trick iOS into running Shortcut automations that the OS doesn’t typically allow you to do.

A week ago I posted about how to triage your email in the car with Siri and a little server-side magic. Tonight I’m going to hack together a Shortcut that automates something I’ve done nearly every afternoon, five days a week, for the last thirteen years: tell my wife I’m leaving work.

I have a shitty commute each day from one side of Nashville to another. The mornings aren’t too horrible, but my afternoon drive home is almost always an hour. And the first thing I do as I pull out of the work parking lot is tap Waze to get a traffic estimate and either text or call my wife to let her know I’m leaving and how long it’s probably going to take. This didn’t matter so much the first eight years of our marriage, but now with two kids who have school schedules of their own, every little bit of coordination helps.

If you’ve played around with Shortcuts.app much, you’ve probably noticed two things:

  1. There’s an intriguing action to compose and send a text message to someone.
  2. In iOS 13 there’s a new (it is new in iOS 13, right?) “Automation” tab that lets you schedule certain shortcuts to run automatically.

I’m a big fan of automating my computers as much as possible. So this suddenly being available on my trouser Mac has my mind spinning with the possibilities.

Sadly, a ton of the endless automations I can dream up are just not possible because Apple simply restricts what can happen automatically. I assume this is for privacy reasons. And I can’t really blame them. As an example, what if someone got ahold of your phone and set a shortcut to automatically text your most recent photos to everyone in your address book every time you left the location of your favorite night club? Not good.

But, as a power user, I crave this type of, well, power over my device. I would love an “I’m not an idiot” switch to bypass these safety protections. Until then, here’s what I’m doing to hack around it.

My ideal use case is this: when I leave work in the afternoon, fetch the estimated drive time home and text it to my wife. It’s that simple. Here’s what the Shortcut would normally consist of…

And then you’d just hook it up to an automation that runs it when you leave work in the afternoon like so…

But, like so many of iOS’s restricted Shortcut actions and Automations, sure, it’ll run – but it doesn’t actually do anything until you tap on a notification it presents and then unlock your phone to give it permission.

We can do better.

At first I thought: “OK, I have a ton of server side experience. I’ve written code to work with Twilio’s awesome SMS sending service many times. If iOS won’t let me send an iMessage automatically, I’ll just make it ping my server and send a real SMS for me.”

Cool, cool.

So I whipped up a quick PHP script that accepts a message POSTed to it from the Shortcut and then texts it to my wife via Twilio. And it works great!

But! I quickly discovered that not only are some Shortcut actions restricted from running automatically, but certain Automations are as well. And location based triggers are one of them that iOS won’t run without your consent each time.

After doing a ton of googling, I found this Apple support document that reads:

The following automations cannot be run automatically:

  • Arrive
  • Before I Leave
  • Bluetooth
  • Leave
  • Time of Day
  • Wi-Fi

Crap. So, I can’t trigger the Shortcut based on leaving a location. But higher up in that support doc are triggers that do run automatically…

  • The following automations can be run automatically:
  • Airplane Mode
  • Alarm
  • CarPlay
  • Do Not Disturb
  • Low Power Mode
  • NFC
  • Open App
  • Watch Workout

Bingo. I added CarPlay to my Subaru recently. I can set the Shortcut to run when I connect to CarPlay.

But that’s not quite right. I don’t want her to get a random text from me every time I get in my car. Only when I’m leaving work in the afternoon.

The solution I came up with took some fiddling to get just right, but it works flawlessly. Here’s the full Shortcut, which I’ll explain below:

Since I want this Shortcut to run automatically, I need to hook it up to an Automation that can run things automatically. In my situation, that’s my phone connecting to CarPlay.

But, I only want the Shortcut to actually execute when I leave work. That means, it needs to be gated by the following conditions so my wife doesn’t receive unnecessary texts:

  1. I have to be currently at work. (So that the Shortcut runs when I’m leaving work.)
  2. It has to be at the end of the day. I don’t want it to trigger when I leave on my lunch break.

So, the first action gets my distance in miles from my current location to my work address (blurred out).

Then, if I’m within a quarter of a mile, the Shortcut continues. (Funny: my first pass at this script had the distance threshold set to one mile. She got a text when I left work, and then five minutes later when I left the gas station after buying a Zebra Cake.)

Next, we need to restrict it to the end of the day. For me, I consider this after 3pm. That’s well past when I would leave for lunch. But also early enough for when I do occasionally leave to pick up my kids instead of her.

And that time restriction was tricky to implement. Maybe there’s a simpler way in Shortcuts.app, but I couldn’t find a way to compare times – only dates. So, I first had to construct a data value for 3pm on the current day. And then compare that to the current date and time. If that computed date was earlier than the current date, that means it’s past 3pm and we’re good to finish running the script.

And then the final step is to POST the travel time home to my web server which handles sending the text message to my wife since even with an automatically run automation, iOS still prevents you from sending a text message without confirmation.

So, that’s it. Like my previous post about Siri and email, I’m beginning to realize that you can do a little server-side processing to augment and flesh out what iOS allows the Shortcuts app to do. And I think we as a community are just beginning to scratch the surface of what might be possible in the future as these always-online, location-aware devices become more and more capable of doing our bidding.