Connecting nvALT and Address Book

[Tweet : ADN : nvALT]

Here’s a quick, simple AppleScript to help you hook Notational Velocity/nvALT into Address Book. I sometimes want to attach a note or list of links to an entry in my address book, but I don’t like using the notes field. I tend to keep all of my notes1 in nvALT, and I prefer not to scatter them too far. All I needed was a way to quickly create and link an nvALT note to each address…

As of recent versions, Notational Velocity and nvALT have a URL handler for nv:// (or nvalt://). Using the /find/ parameter allows you to initiate a search in NV from a link, e.g. nv://find/abnote%3AJohnny Appleseed. If you use a unique prefix and full name, you can pinpoint a single note without having to create a file or locate the note’s ID. The first time you click the link, it will open a search in NV, and pressing Return will create the note and begin editing. Once the note is there, it will locate it instantly the next time you click the link.

I’m using the prefix “abnote:” on my notes. This AppleScript will create the URL entry automatically from the selected entries’ first and last names, and you can edit the prefix in the script to be anything you like. Just save it as “Add NV Note.scpt” in ~/Library/Scripts/Applications/Address Book and it will show up in your script menu2 when you’re in Address Book. You can run it on a bunch of entries (it’s not optimized to run on an entire large address book, though), or one at a time as you need it.

I wrote this on Lion. I honestly have no idea if it works on anything earlier. It might3.

The script

tell application "Address Book"
	set thePeople to the selection
	repeat with thisPerson in thePeople
		set theName to name of thisPerson as string
		make new url at end of urls of thisPerson with properties {label:"NV Note", value:"nv://find/abnote%3A" & theName}
	end repeat
	save
end tell
  1. Notes, for me, are different from log entries. I actually like keeping those separate most of the time.

  2. Enabled in AppleScript Editor, Preferences->General->Show Script menu in menubar. Or better, use FastScripts.

  3. It might not.