I recently started working as a Mac Developer at Sketch, which is a fully remote company. Anyone who has ever worked in such an environment knows that the remote style of working and living has its own perks and challenges, and one of those challenges certainly is communication. Which is why many fully remote companies have established a certain etiquette, and Sketch is no exception.
At Sketch, we make good explicit and implicit use of Slack for our conversational needs. We update our status as needed and communicate in our #general channel when
we get to work, take a break, go exercise or have lunch. And being the curious, nerdy – not to mention forgetful – person I am, I instantly started wondering if I can automate this somehow to make the process frictionless and easy.
Short of installing some sort of physical buttons on my desk, I thought that using NFC tags would be a good candidate for this feature. I could get up from my desk, quickly touch my iPhone to the appropriate tag and the machines would take care of the rest while I’m already on my way to the coffee machine. Wonderful!
After going through a few options of how to set this up – some of which would have required paid subscriptions or authorization from the Slack owner – it dawned on me that I could try something relatively simple: use AppleScript to make Slack do this, as opposed to IFTTT, Zapier or something along those lines.
And as it turns out, someone named Sam Knight was kind enough to write a set of AppleScript definitions for Slack which I could make use of. To make it work with my current version of Slack (4.3.3), I just needed to make one small change, and I was good to go.
I ended up writing two scrips at first, one to set myself away (brb) and one for returning to work. These are probably the most common scenarios for me, as I might step out for just a moment between tasks, to get coffee, take a short break for whatever reason. The scripts for this look like this:
tell script "Slack" focus main window focus workspace "Sketch" focus channel "general" set status "brb" with icon ":brb-small:" send message "brb" end tell
And for returning:
tell script "Slack" focus main window focus workspace "Sketch" focus channel "general" set status "Fixing bugs" with icon ":happymac:" send message "back" end tell
There, pretty easy. However, the last piece of the puzzle was still missing. How could I get my iPhone to invoke these scripts on my Mac in response to scanning an NFC tag? I was aimlessly browsing through the various actions in the Shortcuts app until I found it: Run script over SSH
That was exactly what I was looking for. I copied the SSH key from the Shortcuts app into my authorized keys file, added the hostname and osascript command and I was ready to go.
I just had to add some colorful NFC tags and I was done:
Steps to follow if you want to do this yourself:
1. Download the Slack AppleScript definitions from my clone of Sam Knight’s repository and follow the installation instructions
2. Create scripts for actions you would like to automate (using Apple’s Script Editor), either according to my examples above to or build your own using the instructions in the README file
3. In Shortcuts, set up a new personal automation based on an NFC tag trigger using the Run script over SSH option
4. Configure the host and user for your Mac and send yourself the public key by tapping on ed25519 key, followed by Share Public Key
5. Add the public key to your `.ssh/authorized_keys` file
6. Configure the osascript command to execute the script(s) you’ve created