Having recently started using a treadmill desk, I wanted to automate actions on OS X as I switched from the regular desk to the treadmill. For example, turn on Bluetooth, switch the audio output device, etc. Sure, I can do that by creating an Automator script I’d run somehow, but I was curious to see if I could make it happen just by placing my phone on the treadmill desk.
Here’s how I do that using a few apps and utilities.
Requirements:
- IFTTT and Dropbox accounts (you don’t actually need the apps on your phone)
- Android:
- NFC capable phone, and NFC sticker
- Trigger
- OSX
- Hazel
- Dropbox
- Blueutil to toggle bluetooth
- Switchaudio-osx to switch audio output device
Setup
IFTTT
- Connect to the Maker and Dropbox channels.
- Note your Maker channel secret key
- Create a recipe with Maker’s receive a web request trigger and Dropbox’s create a text file action. You can use this recipe as a template. The file name’s and contents don’t matter. Choose a meaningful event name.
- Test your maker trigger url in the terminal with
[code lang=”bash”]
curl -X POST https://maker.ifttt.com/trigger/{event}/with/key/{key}
[/code]
Android
- Launch Trigger and add a new task.
- Add an NFC trigger and (in the following screen) any applicable restrictions.
- Add an action, and select “Open a URL/URI” under Applications & Shortcuts.
- Enter your trigger url, and mark “Open in background”.
- When prompted, program your sticker.
Note: I’ve tried placing the sticker on the mac itself, but that didn’t work. I’m guessing there’s too much RF interference.
OSX
Setup Hazel as follows:
- Add your new dropbox sub folder (in ifttt/maker/event_name, by default) to the Hazel folder list
- Add a folder rule for new files (see screenshot below). Add any actions you’d like to run: I move the file to the trash, and run an embedded shell script to launch some apps and command line utilities.
That’s it! Every time you’ll place your phone on the NFC sticker, it’ll make an HTTP request, which will cause a file to be created in a dropbox folder. After the brief sync delay, Hazel will recognize the file and launch any actions you’ve told it too.
Leave a Reply