samhuri.net


By Sami Samhuri

Linky

Send links from mobile devices to your computers.

The last few months I've been annoyed by my workflow for sending links from my touch devices to my computers. For example if I come across a cool Mac app or an open source project I want to check out, or anything along those lines. Until now I have been mailing links to my work or home addresses, or saving links in Instapaper. The problem with both of those is the same: I have to remember to check something when I arrive at the correct machine. It sounds trivial but I have been annoyed by it nonetheless.

This weekend I finally decided to scratch that itch and ended up writing much less code than I imagined to accomplish it in a perfectly acceptable way. The components are:

Yup, that is a lot of moving parts. It is rather elegant in a Unixy way though.

I experimented with Gmail → IFTTT → BoxcarGrowl, but Boxcar's Mac app is really rough and didn't seem to pick up new messages at all, let alone quickly, so I fell back to a solution with more parts.

Gmail

Gmail allows you to append extra info to your email address in the username, which you can use for filtering and labeling. I send links to sami.samhuri+linky@gmail.com and then filter those messages out of my inbox, as well as applying the label linky. Using email as the entry point means that basically every app I use already supports sending links in this way.

IFTTT

IFTTT (If This Then That) can wire up services, so that events that happen in one place can trigger an action elsewhere, passing along some info about the event along with it. In this case when a new email arrives in my Gmail account with the label linky then I create a text file in Dropbox that contains two lines: the title, followed by the link itself.

For example, the following lines would be created in a file at ~/Dropbox/Linky/Ruxton/<generated filename>.txt for my machine named Ruxton.

Callbacks as our Generations' Go To Statement http://tirania.org/blog/archive/2013/Aug-15.html

The filename field is defined as:

{FromAddress}-{ReceivedAt}

And the content is:

{Subject}
{BodyPlain}

That means that when you email links, the subject should contain the title and the body should contain the link on the first line. It's ok if there's stuff after the body (like your signature), they will be ignored later.

I create one recipe in IFTTT for each machine that I want links to appear on. You could get fancy and have different Gmail labels for individual machines, or aliases, groups, etc. I've kept it simple and just have every link I send go to both my home & work computers.

Dropbox

Dropbox is fantastic. My files are never not everywhere. IFTTT creates the file in Dropbox, and then Dropbox makes sure it hits all of my machines. Did I mention that Dropbox is awesome? It's awesome.

NorthWatcher

This is a quick and dirty thing I whipped up a couple of years ago, and now it's come in handy again. It's a program that watches directories for added and removed files, and then launches a program that can then react to the change. In this case, on each machine I want notifications on, I have it watch the Dropbox folder where IFTTT creates the text files. e.g. ~/Dropbox/Linky/Ruxton

It has a text configuration file kind of like cron. Here's mine from Ruxton:

That tells NorthWatcher to run ruby /Users/sjs/bin/linky-notify when files are added to the directory ~/Dropbox/Linky/Ruxton.

NorthWatcher is on GitHub and npm. Install node and then run npm install -g northwatcher. After creating the config file at ~/.northwatcher you can run it automatically using this launchd config file. Drop that in ~/Library/LaunchAgents/net.samhuri.northwatcher.plist. Don't forget to update the working directory path, and run launchctl load ~/Library/LaunchAgents/net.samhuri.northwatcher.plist to load it up (afterwards it will load on boot).

A Ruby program, and terminal-notifier

Finally, we have the last two components of the system. A short Ruby program (/Users/sjs/bin/linky-notify) that reads in all the files NorthWatcher reports as added, and uses terminal-notifier to show a native OS X notification for each link. After displaying the notification it moves the text file into a subfolder named Archive, so I have a record of all the links I have sent myself.

You can get terminal-notifier with homebrew in a few seconds: brew install terminal-notifier. After you have used terminal-notifier you will be able to go into Notifications in System Preferences and change it from Banners to Alerts. Banners are transient, while Alerts are persistent and have action buttons: Show and Close.

Cool story, bro

It may not be exciting, but as someone who typically suffers from NIH syndrome and writes too much from scratch, I found it pretty rewarding to cobble something seemingly complicated together with a bunch of existing components. It didn't take very long and only involved about 10 lines of code. It's not exactly what I wanted but it's surprisingly close. Success!