Get person from selection in AddressBook

There must be an easier way to get the person from the selection in AddressBook. Be compassionate I’m a noob.

tell application "Address Book"
	set numberOfPeople to count selection
	set selectionList to the selection
	repeat with x in selectionList
		set personID to (id of first item of x)
		set myPerson to (first person whose id is personID)
		set fname to first name of myPerson
		set lname to last name of myPerson
	end repeat
end tell

My method seems a little redundant, what am I missing?:confused:

Model: PowerMac G5
Browser: Safari 523.10.6
Operating System: Mac OS X (10.5)

Hi Michael,

selection contains a list of persons,
you can access the elements and properties directly.
The result of your script is always first and last name of the last item of the selection,
I’ve put them in a list


tell application "Address Book"
	set {fname, lname} to {{}, {}} -- reset the variables
	repeat with x in (get selection)
		set end of fname to first name of x
		set end of lname to last name of x
	end repeat
end tell

Well not really.

tell application "Address Book"
	count every selection of current application
		2
	get selection
		{person id "0AAFB6B1-082A-4475-863C-9BFBF9898D1C:ABPerson", person id "4AEA8603-FBA8-4C87-9A96-9A9D3CCCCC92:ABPerson"}
	get id of item 1 of person id "0AAFB6B1-082A-4475-863C-9BFBF9898D1C:ABPerson"
		"0AAFB6B1-082A-4475-863C-9BFBF9898D1C:ABPerson"
	get person 1 whose id = "0AAFB6B1-082A-4475-863C-9BFBF9898D1C:ABPerson"
		person id "0AAFB6B1-082A-4475-863C-9BFBF9898D1C:ABPerson"
	get first name of person id "0AAFB6B1-082A-4475-863C-9BFBF9898D1C:ABPerson"
		"Thomas"
	get last name of person id "0AAFB6B1-082A-4475-863C-9BFBF9898D1C:ABPerson"
		"Krawczyk"
	get id of item 1 of person id "4AEA8603-FBA8-4C87-9A96-9A9D3CCCCC92:ABPerson"
		"4AEA8603-FBA8-4C87-9A96-9A9D3CCCCC92:ABPerson"
	get person 1 whose id = "4AEA8603-FBA8-4C87-9A96-9A9D3CCCCC92:ABPerson"
		person id "4AEA8603-FBA8-4C87-9A96-9A9D3CCCCC92:ABPerson"
	get first name of person id "4AEA8603-FBA8-4C87-9A96-9A9D3CCCCC92:ABPerson"
		"Darrell"
	get last name of person id "4AEA8603-FBA8-4C87-9A96-9A9D3CCCCC92:ABPerson"
		"Wilson"
end tell

Thanx for your help!

of course it gathers all names in the repeat block,
but the final result of the script is the name of the last loop,
the previous names get lost :wink:

Okay, I see what you mean. It was my intention to do the work in the repeat block. I had shortened the script for brevity’s sake.

Thanks