but you knew that
January 19, 2013
tags: alfred, grep, dropbox, markdown, iA Writer, spotlight
I'll echo the thoughts of @MattAnderson99 and @xagronaut in saying, while at Codemash this year, I attended an interesting open source session for life hacks. The session gave me some new ideas for my digital note-taking process.

There's not much heavy lifting for this process. In fact, my contribution to the process is embarrassingly thin. Nonetheless it's a nice example of the power of "small pieces loosely joined"[1] , which might be my favorite kind of geek fun.

[1] I first heard this term from Eric Meyer in his "Evolution of the Web" presentation he gave at Stir Trek 2012. My notes are vague[2] but given the nature of the talk, I'm sure he was referencing the book Small Pieces Loosely Joined written by David Weinberger.
[2] I keep a pdf of the Cornel Notes Template in my Moleskine. Fat lot of good it does me. In addition, sketch notes has me intrigued. Check out Binaebi Akah's and Mike Rohde's stuff.
Plain Text
As in plain old simple text. Not to be confused with the iPhone app, PlainText. I'll talk about that later.
I take notes on my mac in plain text, usually formatted in markdown. For me, plain text means simple and portable which is a powerful combination.
I add tags to my notes by prepending a "!" in front of the tag text. That's it. No really. That's it.
One caveat: You'll want to put some thought behind how you define a tag. If you go with prepending a character like I'm doing with the '!' it's nearly impossible to avoid grabbing some extraneous words. For example, my first choice was to prepend a '@' but then too many email addresses were muddying up my search results. Instead of prepending or appending a single character, surrounding a word (!books!) might be a better approach.
The Joining of the Pieces
Now it's just a matter of coming at the data from different directions. What follows are a handful of tools that I'm using for my plain text mining.
This is simple. I just let Spotlight do what Spotlight do.

For example, say I'm scanning my twitter feed when I see a recommendation for a book that interests me. I open my ToRead_books.txt file and add the tweet. Like so:
Notice line 5 where I added the !books text.

And look at the results I get when I fire up Spotlight and search for !books.

The first option listed is my text file. Cool, huh?
find & grep
So what are all my tags? find and grep can handle that task. Here's the bash script that lists all my tags.
find /Users/mark/Documents/markdown_notes/data/markdown/ /Users/mark/Dropbox/notes/ -name "*" -exec grep -hoEI "\\!(\\w+?)\\b" {} \; 2>/dev/null | sort -f | uniq
I'll save you the exercise of running man grep
  • -h: Never print file headers
  • -o: Prints only the matching parts of the lines
  • -r: Recursively search subdirectories listed
  • -E: Interpret pattern as an extended regular expression
  • -I: Ignore binary files
I put the script in my path and when I run it, usually from Alfred, I get something like this:

mytags results


Alfred preferences Alfed setup

but wait, there's more!
It's just plain text, grep, and find so the myriad ways I can slice and dice the data are limited only by my imagination.

Just for arguments' sake, say I'm procrastinating and have already surfed most of the web. The next thing I might do is list all my tags and, in so doing, I see that I have a tag of '!to_read'. My next logical question is "to read what?" Well, I've written a couple of scripts for that.

Here's a script that lists all my files that have tags in them.

 find /Users/mark/Documents/markdown_notes/data/markdown/ /Users/mark/Dropbox/notes/ -name "*" -exec grep -rlEI "\\!(\\w+?)\\b" {} \; 2>/dev/null | sort -f | uniq

The tagfiles.sh script is just a support script though. My tagsfortag.sh is the script that tells me, for a given tag, what additional tags are listed. In other words, for all the files with tag_1, list all the tags in only those files.
Here's that script:

./tagfiles.sh | xargs grep -l "$1" 2>/dev/null | xargs grep -horEI "\\!(\\w+?)\\b" | sort -f | uniq

And now, from the subset of files that has a !to_read tag within it, here's a listing of my tags from just those files:
tagsfortag results

Golf and computers. Big surprise.
Dropbox is what I'm using to sync my notes between my iPhone and my macbook. Nuff said.
iA Writer
There are plenty of options for plain text editors for your iPhone that also incorporate Dropbox. I did a tiny amount of research and settled on iA Writer. Initially, I was using PlainText but I'm much happier with iA Writer because of how it synchs with Dropbox.
Simple plain text is the engine that powers the process but it's not always the best for visual presentation. I use markdown and a couple tools, listed below, to help with that.
markdown quicklook plugin
Another tool that I find useful is Michael Dominic Kostrzewa's markdown quicklook plugin. It's a handy tool that, after using Spotlight to locate a file, when I hover over the file, I see the markdown text rendered as html.

Like so:

I use vim for text editing. The following line in my .vimrc, given to me by fellow Pinnacleer @bhfSteve, allows me to take advantage of the above plugin while I'm editing the file.
map <leader>v :write<cr>:sil !/usr/bin/qlmanage -p -x % > /dev/null <cr>:redraw!<cr>
Now I have a quick way to preview my file. For example, while editing a markdown file in vim, when I hit the key chord '<comma>-v' I'll see a preview pane just like the recursion markdown example shown above.
With one simple convention (the prepended '!') and basic, existing tools, I have a process that ...
Surprise Ending
Don't do this. Just use Evernote (or Catch).
Mark Haskamp
navigating crankiness toward simplicity