Mac automation is something we’re pretty big on at Envato Tuts+. With tools like Keyboard Maestro and Hazel you can do a lot. By linking different services together, however, you can add even more ways to control a Mac. Even when you’re nowhere near it.
To follow along with this tutorial you will need both an IFTTT account and a Dropbox account. You’ll also need an automation app like Keyboard Maestro or Hazel that will do the hard work on the Mac. Which one you use is up to you.
I’ve already covered a lot of the fundamentals of these tools so before continuing with this tutorial you should read:
- Journal Your Life with Day One 2 and IFTTT,
- How to Choose the Right Tools to Automate the Mac, and
- My five part series on Keyboard Maestro, or
- My four part series on Hazel.
How This Works
In this tutorial I’ll focus on the mechanics of the trigger rather than the specific action it runs afterwards. You can use either Keyboard Maestro or Hazel and Automator to achieve the same results—Keyboard Maestro just makes it a little more intuitive.
I’ll use IFTTT to create a trigger file in Dropbox. This trigger file will contain a code that the automation app reads and then runs the relevant action.
For this tutorial, I’ll create a IFTTT DO button that when I press it, my Mac gets set up to watch movies.
Creating a Trigger File With IFTTT
Log in to the IFTTT account and ensure Dropbox is one of your connected channels, if it isn’t, set it up now.
On an iPhone, download the IFTTT DO app and sign in to your IFTTT account. This will automatically activate the new channel.
Using the iPhone, create a new DO recipe using the Dropbox channel. I want IFTTT to Create a text file in Dropbox that will automatically sync to the Mac.
I’m calling this recipe Launch Movies. My text file is called DoSomething which will be the same for any action I create. For this example, I want the Content to be #movies. Finally, I’ve set the Dropbox folder path to DO; that will be the folder where the trigger file is created.
With that done, the DO button is ready to use. Try it out.
Reading the Trigger File
Now that we’ve got a way to quickly add a trigger file to Dropbox, it’s time to look at reading it.
Create a new Macro and call it something like IFTTT Automation. Set the Trigger to a Folder Trigger. Click the Folder icon and navigate to your DO folder. Make sure adds an item and ignore partial files are selected. Whenever a file is added to the folder, the action will trigger.
Next, I need to find out what action we have to run. This means reading the contents of the DoSomething text file. If you have’t already done it, run the action once so there is a file in the folder to work with.
Add a new Read File action from the File folder. Set it to read dosomething.txt to a variable. I’ve called the variable Command. Now whenever a new file is added to DO, whatever its contents are will be saved to a variable. We can use this to determine which action runs.
To finish things off, add a Delete File action and target dosomething.txt. This will reset everything.
To trigger the different commands, add a Switch from Command Flow. Set the Switch to If Variable Command.
For each command you have, add a series of actions. For example, I’ve set mine so that if Command contains #movies Keyboard Maestro launches Plex and Plex Media Server, turns the screen brightness up to full and turns the volume up to full.
Create a different switch option for every command you want.
With Hazel things are a little more awkward. It’s easy to trigger but you need to use AppleScript to manage the actions.
First, create a new AppleScript in the Script Editor. Add whatever actions you want. For me, I want Plex and Plex Media Server to launch so my script looks like this:
tell application "Plex Media Server" activate end tell tell application "Plex" activate end tell
Save the script in a good location. I have an Operations folder in my Dropbox for these sort of things.
Open the Hazel Preference Pane and create a new rule targeting the DO folder. Set it so that if the Name is dosomething and the Contents contain #movies the script you created is run and the file is moved to Trash.
Repeat this process for every action you want.
Coming Up With Other Ideas
Using a simple text file in Dropbox let’s you link all IFTTT’s three hundred plus channels to your Mac. I’ve used a DO button as an example but you can easily have actions triggered by any of the other channels. TJ Luoma over at MacStories uses Automatic and a geofence to trigger his Mac when his car is turned on or off in his work’s parking spot.
There’s really no limit to what you can do. If you want something to happen on a Mac whenever you’re tweeted at, a RSS feed updates or anything else, you can do it. Just create an action that does what you want and use Keyboard Maestro or Hazel to trigger it.
Over the next few tutorials, I’ll be digging into a few of these different ideas.