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.