Note to Self

Friday, June 3, 2011

Here’s the basic problem: You’re reading Twitter, or Tumblr, or some such on your iPhone, and you come across something you can’t process on your phone. Maybe it’s a download link for a zip file of songs. Or a snippet of code that needs to go in your next build. Or (God help you) a Flash site. Basically, you need it on your computer to do something with it. If your phone and computer are on the same network you can use Pastebot. But what if they’re not?

I often find myself away from my computer and finding something I want to look at on my computer, but none of the services I use are appropriate. I don’t want to throw it into Instapaper if it’s not an article. I could throw it into OmniFocus, but it doesn’t really qualify as a to-do, and I’m really trying to keep OmniFocus limited to project tasks. I have various apps I could use to make a note, but I need some kind of prompt to let me know I have things in notes I need to process. That’s what led me to come up with this little workflow.

In a nut: I paste whatever it is into a text file. Next time I’m at my computer, that note will appear as an HTML page in a tab in Safari. It comes up automatically, so I don’t have to go looking for it.

Now, here’s how I did it: I use PlainText (my current preference, lots of iOS apps provide the same functionality) on my iPhone and iPad for notes. PlainText syncs with Dropbox, allowing me to edit any text file I have there. In it, I have a file named “look at on mac.txt”. Whatever I want to send to my Mac I write there in Markdown format (more on this in a second).

On both my laptop and desktop I created a LaunchAgent. This is a special service in OS X that can, among other things, watch a specific file for changes and run a script when that file changes. Easiest way to create LaunchAgents is with Lingon, it will step you through the process. This agent watches “look at on mac.txt” and runs the following script when it changes:

#!/usr/bin/env bash

if [[ -s /users/billy/Dropbox/Notational\\ Velocity/Look\\ at\\ on\\ mac.txt ]]; then
    /usr/local/bin/multimarkdown /users/billy/Dropbox/Notational\\ Velocity/Look\\ at\\ on\\ mac.txt > /users/billy/Dropbox/Notational\\ Velocity/notetoself.html
    open /users/billy/Dropbox/Notational\\ Velocity/notetoself.html

If the file has anything in it, this script runs MultiMarkdown to convert the text to HTML and save it as a separate file. Then it opens that file in the default web browser (in my case, Safari).

This works pretty well for me. I can copy and paste, then put my device away knowing the thing I need to look at will be right in front of my face next time I sit at my computer. The one “uneven” part of this is I have to go back and delete stuff from the text file when I’m done with it. I could make the script delete the contents of the text file after generating the HTML, but that would mean the note might only be on whichever computer synced with Dropbox first.

One other thing to note: LaunchAgents are temperamental beasts. If you update the file often in a short period of time, launchd (the process that runs LaunchAgents) will throttle your agent. Sometimes, it doesn’t recover from that, and has to be unloaded and reloaded before it will work again. In my experience this is easy to do while you’re testing, less so in real-world usage.

After getting this working I looked to see if anyone had done something similar. This article from MacStories shows how to have URLs opened automatically by sending an email to Dropbox. Whatever works for you. For me, I didn’t want to use email, and I wanted the option to display any text, not just URLs.