Address Book scripting

I’m searching for the way to display a choosen contact in the address book.
Tried “set selection to…” but was unsuccessful.
Anybody having the clue?
Thanks

I believe that although the dictionary says Address Book’s selection is read/write, this is a lie.

Well, after I analyzed the Apple Event transactions for the wonderful utility Quicksilver, I discovered that Address Book registers the protocol ‘addressbook:’ What this means is that if you attempt to open the URL 'addressbook://SOME_PERSON_ID" the Address Book will open to that person’s information.

Here’s a sample script:


set nameDialog to (display dialog "Enter the name to search for:" default answer "")

set nameToFind to text returned of nameDialog

tell application "Address Book"
	set foundContactList to (id of every person whose name is nameToFind)
end tell

if (count of foundContactList) is 0 then
	display dialog "No contact found with that name."
	return false
end if

if (count of foundContactList) is greater than 1 then
	
	display dialog "Multiple contacts found with that name - will display the first one."
end if

open location "addressbook://" & (item 1 of foundContactList)

Oh, by the way, to watch the Apple Event log for an application, do the following (leave out quotes around each thing I say to type):

  1. Open a new window in the Terminal.
  2. Type: ‘setenv AEDebug 1’ and press return.
  3. Type: ‘setenv AEDebugSends 1’ and press return.
  4. Type: ‘setenv AEDebugReceives 1’ and press return.
  5. Type the FULL PATH to the application and press return. For applications that are bundles, this means you need to include the executable inside the application bundle. For example, Quicksilver on my machine is at:
/Users/krioni/Applications/Quicksilver.app

So I needed to type in:

/Users/krioni/Applications/Quicksilver.app/Contents/MacOS/Quicksilver

since the application is really a bundle.

You will get a lot of seemingly-garbled text while the application launches and runs, but this is basically just the Apple Events to and from the application, displayed in a specific format.

Enjoy!

Very clever, Krioni! I remember reading about that now.