Drag and drop from Address Book?

I’m currently trying to create an app that contains a Table View with two columns. The first one contains a person’s name, the second column the corresponding email address. At the moment, you can only add people’s names+email addresses by typing them in. I was thinking of adding some drag and drop support, but I’m puzzled as to how to proceed.

I tried drag and drop information from Address Book. When I use this code:

on drop theObject drag info dragInfo
	set vCard to {}
	set preferred type of pasteboard of dragInfo to "vcard"
	set vCard to contents of pasteboard of dragInfo
	log vCard
end drop

I get an error message saying: “The variable vCard is not defined. (-2753)”

Maybe I’m doing this all wrong. What would normally be the best way to make use of the Address Book in this sort of scenario?

Okay, I got something that actually works. After a lot of poking around in the dark I came up with this:

on initiate_ table_view(table_view)
	tell table_view to register drag types {"vcard"}
end initiate_ table_view

on drop theObject drag info dragInfo
	set id_list to {}
	set preferred type of pasteboard of dragInfo to "dyn.agu8ycuwuqz11a5dfnzeyk64uqm10c6xenv61a3k"
	set id_list to contents of pasteboard of dragInfo
	repeat with current_ID in id_list
		tell application "Address Book"
			set the_vcard to vcard of item 1 of (every person whose id = current_ID)--This takes for ages!!!
		end tell
extract_info_from_vcard(the_vcard)--handler to extract useful information from vCard
	end repeat
end drop

The problem is that it is incredibly slow when running in ASS. The (tell application “Address Book”) block seems to be the guilty party. The weird thing is that it runs fine in Script Editor, no delays. But in ASS it hangs for close to 10 seconds.

Hi,

what’s about using the people picker?
Take a look at the TogglePeoplePickerDrawer project of JNSoftware

Thanks, I wasn’t aware of the people picker.