Trunk Notes lookups from the desktop

Trunk Notes Overview

One of the most useful apps I have discovered for the iPhone is called Trunk Notes.  Effectively, it is a “wiki” or series of interlinked notes, that you can carry around in your pocket.  I actually don’t use it so much for the interlinking — tagging and search are plenty enough for me — but this app really shines in two features that are certainly not available in the built-in Notes app and which are a bit rare on other apps.

The first of these two features is WiFi sharing.  When you enable this, it turns your phone into a little webserver that you can get to from your desktop browser.  This makes cutting, pasting, and larger structural edits super-easy because you have a full screen and full keyboard.  You are not constrained by the limits of the iPhone’s screen and keyboard or the multiple gestures required to copy and paste text.

The other key feature is Dropbox synchronization.  As much as I respectfully disagree with some of Dropbox’s recent moves (to the point of moving all but iPhone-synced data to SpiderOak), I have to admit that synchronization between computers and phones via Dropbox is nothing short of magical.

Trunk Notes synchronizes its contents to Dropbox as a collection of text files.  I can then search and edit those on my desktop.  Mainly I search, since it’s easier to edit on the phone or via the WiFi sharing.  I got a little bit tired of constantly running “grep” in my trunksync folder then “less” on the result, so I wrappered it in a shell script.

“Notes” Script Overview

The script itself is called “notes” and lets you place a search term on the command line.  I can enter “notes apple” and it responds with a list of all notes mentioning the term “apple” (in upper or lowercase).

Given this list, I can then select one and bring up the content of the note with my search term highlighted.

Requirements

The “notes” script is a Bash shell script.  This means it will run on Unix or any Unix-like operating system.  These include the stock Linux and OS X installs.  It can also be run on Windows under the Cygwin command shell.  (The details of installing and configuring Cygwin are beyond the scope of this post.  They have some mighty fine documentation.)  To install, you just need to create the script, mark it as executable (chmod 755), and put it somewhere in your path (/usr/local/bin).  If your Dropbox folder is in a different place than your home directory or if you’re syncing with a Trunk Notes folder other than trunksync, then you’ll have to make the appropriate modifications.

Script

The script is as follows:

#!/bin/bash
if [ -z "$1" ]; then
    echo "Put search term on command line"
    exit 1
fi

# Set this to:
#  0 to only show matching notes
#  1 to show matches lines in context first, before printing matching notes
PRINT_MATCHES_IN_CONTEXT=0

# Find matches
LIST=/tmp/notelist.$$.txt
grep -r -i -l "$1" ~/Dropbox/trunksync/notes > $LIST
if [ $PRINT_MATCHES_IN_CONTEXT -eq 1 ]; then
    grep -r -i --color "$1" ~/Dropbox/trunksync/notes
    echo ""
fi

# Display list of matching files
exec<$LIST
COUNTER=1
echo "[0] abort"
while read LINE
do
    FILE=`basename "$LINE"`
    echo "[$COUNTER] $FILE"
    ((COUNTER=COUNTER + 1))
done

# Ask for selection
exec<&1
echo -n "Selection: "
read SELECTION

# Find file that matches selection and display it
exec<$LIST
COUNTER=1
while read LINE
do
    if [ "$COUNTER" == "$SELECTION" ]; then
        less -i -p "$1" "$LINE"
    fi
    ((COUNTER=COUNTER + 1))
done

# Clean up temp file
rm -f $LIST
Posted in: Code iPhone

Published by

Brian Enigma

Brian Enigma is a Portlander, manipulator of atoms & bits, minor-league blogger, and all-around great guy. He typically writes about the interesting “maker” projects he's working on, but sometimes veers off into puzzles, software, games, local news, and current events.

One thought on “Trunk Notes lookups from the desktop”

Leave a Reply

Your email address will not be published. Required fields are marked *