Script for linking from Address Book

Well, here in Europe we don’t use middle names not much. But, here’s a new version that includes also the middle name in the PDF. Making the link clickable is a hard task as modifying RTFs using AppleScript is complicated and error-prone. So, I left this as is for the moment.

-- Create an RTF document with a link to an address book record 
-- Created by Eric Böhnisch-Volkmann on Thu Sep 7, 2006. 
-- Copyright (c) 2006. All rights reserved. 

property pLocation : "/"

using terms from application "Address Book"
	
	on action property
		return "phone"
	end action property
	
	on action title for p with e
		return "Create RTF in DEVONthink"
	end action title
	
	on should enable action for p with e
		return true
	end should enable action
	
	on perform action for p with e
		if company of p then
			set theName to organization of p
		else
			set theName to (first name of p) & " "
			if (middle name of p) is not equal to "" then
				set theName to theName & (middle name of p) & " "
			end if
			set theName to theName & (last name of p)
		end if
		addToDEVONthink((id of p), theName)
	end perform action
	
end using terms from

on addToDEVONthink(id, theName)
	tell application "DEVONthink Pro"
		if not (exists current database) then error "No database is in use."
		set theLocation to create location pLocation
	end tell
	set theURL to "addressbook://" & id
	tell application "DEVONthink Pro"
		tell application "DEVONthink Pro" to create record with {name:theName, type:rtf, URL:theURL, rich text:theName & ", <" & theURL & ">" & return & return} in theLocation
	end tell
end addToDEVONthink

Command-click into the link to place the insertion caret into it. Then use the arrow keys and the Shift key to select the text of the link.

Eric.