Applescript and Notational Velocity
This post was originally published on my old blog as Applescript and Notational Velocity.
In an earlier post, I explained how I use plain text files and Notational Velocity as a task-management alternative to the GTD program Things. Towards the end of that post, I also hinted that I have been able to automate parts of my system by using some Applescript and Automator tricks. Most of these tricks depend on using an apparently little-known feature of Notational Velocity, which is the ability to perform the “search” command on your notes using Applescript.
As Notational Velocity users know, what makes the program unique is the fact that most of its functions begin in the “search” bar. If you want to create a note, you go to the search bar, begin typing the title of your new note, and click enter to create it. If you want to open an existing note, you also go to the search bar and begin entering the text that you want to find.
With the release of Version 2.0β4 at the beginning of 2011, however, it became possible to “search” for text strings in NV using Applescript. (If you are new to Applescript, check out the Ultimate Beginner’s Guide.) This makes it relatively simple to write an Applescript that will create a new note in Notational Velocity, like this:
tell application "Notational Velocity" activate search "Name of the new note" tell application "System Events" keystroke return key code 53 set visible of process "Notational Velocity" to false end tell end tell
The first part of this Applescript tells Notational Velocity to search for whatever text is between the quotation marks after
search (in this case,
Name of the new note). The second part of the script uses System Events to simulate the process of hitting return, which you would ordinarily do in Notational Velocity to create your new note after entering its title in the search bar. It also adds
key code 53 (which has the same effect as entering the Escape key) so that the query is cleared from the search bar after the new note is created. Finally, since the first part of the script activated Notational Velocity, thereby bringing it to the foreground, the script concludes by hiding the NV window from view so you can go back to whatever you were doing.
With some slight modifications, you can also use a script like this to enter some text into the body of the new note you create, but more on that in a moment. First, if you are familiar with NV and are following along so far, you’ll probably realize that this script has some important limitations. Namely, if the text string that you’re searching for is already in a note in your NV database, you’ll run into some problems because instead of creating a new note, NV will find the note with that text.
Nonetheless, this script has been useful in helping me to automate parts of my previously-described GTD system. Here’s an example: in a previous post, I explained how and why I use my iPad to grade student papers. I also use my iPad to annotate other documents that need feedback from me. So when I receive a paper to grade or a document to annotate, there are two things I need to do: (a) get the file to my iPad for annotation; (b) add a “to do” (or a
GoodReader versus iAnnotate
When I wrote my earlier post on grading with my iPad, I was using iAnnotate, and sometimes I still do. But I’ve switched to GoodReader for annotating most PDFs, in large part because the process of syncing files to my iPad is easier and more intuitive. Since I wrote my earlier post, GoodReader has also added a full slate of annotation tools that compares nicely with iAnnotate and even adds some features that work better, in my view.
I learned about GoodReader’s killer syncing capabilities from this episode of Mac Power Users, which also discusses lots of other features peculiar to GoodReader. The most important payoff is this: GoodReader allows me to keep particular folders in my Dropbox automatically synchronized between my iPad and my desktop. For example, I have a folder in my Dropbox called “annotate.” I have set up GoodReader so that this folder is synchronized on my iPad. So whenever I add a file on my laptop to the “annotate” folder, I can get this file on my iPad just by tapping the “Sync” button in GoodReader. Then, when I annotate the file on my iPad, I just tap “Sync” again, and the marked-up file will appear in my Dropbox and on my laptop. Nifty, no?
An example workflow
Now that I’m using GoodReader, Step A of the workflow I described above (getting the file to my iPad) basically means moving the file into my “annotate” folder so that it can be synchronized to GoodReader later. The next step in my workflow is then to add a
To see what my Automator workflow looks like, click on the image below to enlarge.
The first step in this workflow moves the file in question to my annotate folder, so that it’s ready to be accessed on my iPad via Dropbox synchronization. The workflow then passes the name of the file I need to annotate to an Applescript, which creates a note in Notational Velocity that says
qq Read examplefile.pdf. (This Applescript is longer than the one I showed you above, because I don’t want the title of my to-do to include the whole pathname of the file. In this example, I also then have the Applescript put the pathname in the body of the new note, before simulating the Escape key and hiding Notational Velocity from view.)
Sometimes the file I need to annotate comes to me as a Microsoft Word document, in which case I also need to turn the file into a PDF. So I have a separate Automator workflow with an extra step at the beginning that turns Word documents into PDF files. Click the image below to see what I mean.
To make a (potentially even longer) story short, I have saved these Automator workflows as plug-ins for Finder. (I am still using Mac OS 10.5.8, and Automator underwent some significant changes in Snow Leopard, including the elimination of “plug-ins” in favor of something similar called Services) So when I have a file in my Finder that I want to annotate in GoodReader, I basically right-click on the file, navigate to my “To Annotate” workflow, click on it, and voila: the file is moved to my annotate folder, and a new task is created reminding me to read the file. I’ll see that task next time I do my GTD review.
That’s just one example of the kinds of automation I can add into my plain-text GTD system, and it’s certainly the one I use the most. But since you can schedule Applescripts to run on particular dates in iCal, it’s also easy to imagine how you could use a simple Notational Velocity Applescript and iCal to simulate the process of automatically creating scheduled or repeating tasks in Things. But that is a post for another day.
UPDATE: I’ve since figured out how to do this particular workflow much more efficiently using a shell script and the command line. Still, the Applescript functionality of NV might be useful for other workflows.