Add person to group in Address Book?

I’m working on a script to do some special imports of data into the Address Book. Most things work fine. However, I can’t figure out the syntax for adding a person to a group. Should I “make new person at end of group xxx” or use the “add” command to add a “child” record? I’ve not been able to find out much about this anywhere else. Anyone have any ideas? Any code samples? Thanks!!

This might work:

set group_name to "Test Group"

tell application "Address Book"
	set new_ to make new person at end of group group_name
	tell new_
		set first name to "Fool"
		set last name to "Hardy"
	end tell
end tell

– Rob

Rob,

Thanks for the info. That worked to add new people records, but I wanted to link already-existing people records to existing groups. The answer turned out to be more obvious than I thought:

tell application “Address Book”
add ExistingPerson to ExistingGroup
end tell

Boy, do I feel dumb…this seems so simple. But I had to experiment to make sure the “add” command syntax was correct.

This works for me as long as there is at least one custom group defined. The only issue I have found is that the group doesn’t update until I quit and relaunch Address Book:

Jon


[This script was automatically tagged for color coded syntax by Script to Markup Code]

Jon,

Does the ‘save addressbook’ command force the update?

– Rob

Yes, that works, great catch, Rob. Here is a revised script including a slight revision to the search routine to return names that contain the search string, not just exact matches of the last name:

Jon


[This script was automatically tagged for color coded syntax by Script to Markup Code]