Triggering events on macOS from iOS

With my updated Mac mini 1, I've started getting back into looking at automation ideas for my home setup. A recent Mac Power Users podcast hit close to home for me because it was a great discussion by David and Stephen on the recently updated Mac mini. David and Stephen were talking about a possible automation idea that would allow David to automate turning on/off macOS services that would enable David to connect to his Mac using Screenson his iPad.2

Triggering Outline

David's idea motivated me to look at creating a framework that could be easily duplicated to trigger events on my Mac mini from my iPad or iPhone. I wanted a process that would do the following:

  • From iOS, create a trigger mechanism that can use Dropbox or iCloud.
  • From macOS, monitor for the trigger mechanism and initiate an action on the Mac without user interaction.
  • From iOS get confirmation that the trigger action successfully completed.

To set up this automation process, you'll need a few tools on both your iOS device and macOS computer:

From there you'll need to select your cloud platform of choice: Dropbox or iCloud. All the directions listed below will be for Dropbox. The alterations to make the workflow fit for iCloud are pretty minor.

Create trigger file on Dropbox

The initiator to this process is using an action in Shortcuts to create the trigger file in Dropbox. I don't care what the file name is, so I asked one of my kids for a made up word.3

So when this shortcut is run, it will create an empty text file in Dropbox in the designated folder.

Watching for trigger file on macOS

Now that the trigger file has been created, a Hazel rule needs to monitor the folder for the file. Hazel will do 2 things in this example:

  • Remove the trigger file
  • Run an AppleScript.

Applescript FTW

The last piece is what action should take place if the trigger file is found. In my working example I wanted to know what the external IP address is for my Mac mini via an email message. This is the AppleScript embedded in the Hazel rule in the previous step.

The script has 2 parts:

  1. Determine the external IP address of the Mac.
  2. Email the information to a preset email address.

Once triggered, the email will look like this:

Side note: I'll probably update the script to send a Message instead of an email since that's even more universal for my normal workflows.

Wrapping it all up

The main upside of using Shortcuts app, instead of other automation tools, is the Shortcut actions are automatically sync'd across all my iOS devices. So now with one button I can get the current external IP address of my Mac mini from any of my iOS devices.

  1. I still think it should be "Mini" vs "mini" 

  2. Fastforward to about 58 min into the episode.  

  3. I'm thinking of using my kids as my password generator from now on.  

Previous posts:

  1. Adventures in driving

    My adulting life for the past 18 months has allowed me to make frequent trips to the great state of Wisconsin. Normally I wouldn't disparage a state that has such a great selection of craft beers1 and beautiful scenery. But Wisconsin is home to the two biggest annoyances in …

  2. A new way to look at 2019

    Welcome to 2019! 1

    I've spent the afternoon sitting at my desk doing a mix of reading and high level planning for a few projects I know that are coming up this year. A lot of what I've been reading are the affirmations of what everyone is going to do …

  3. iOS Shortcuts - Return to Home Screen

    As I've started to dabble in iOS Shortcuts I've increasingly become annoyed that when a Shortcut is done, especially those that are turned into home screen shortcuts, you aren’t returned back to the home screen. When the shortcut is done you’re left in the Shortcut app.

    After doing …

  4. Rationalizing my choices for the Mac Mini

    My recent internal deliberations on what to replace my ailing computer setup has led to quite a few false starts on what I put into my virtual shopping cart. As much as I wanted to love the new MacBook Air, the power and flexibility didn't hit enough cylinders to trigger …

  5. Pondering next computer purchase

    Like a lot of Apple fans, I watched the presentation by Tim Cook and Co. last Tuesday about Apple’s new fall product releases. The order that Apple presented their new products was absolute genius.

    • Mac Book Air: Here’s a gorgeous new mobile device.
    • Mac Mini: Here’s a …