Address Book Labels

Hey all, I am almost completely new to scripting, with only nominal experience and success.

I am trying to take all the contacts from a smart group and look at every email address for those contacts, and if that email address ends with “edu” I want to change the label for that email address to “school”. I thought this would be pretty simple.

Here’s what I have:


tell application "Address Book"
	
	set emailValue to value of email of (every person in group "Email")
	set emailLabel to label of email of (every person in group "Email")
	set allPeople to id of (every person in group "Email")
	
	repeat with i from 1 to count of allPeople
		if emailValue ends with "edu" then
			set label to "school"
			save
		end if
	end repeat
	
end tell

Something must be amiss, but I don’t know what. Can anyone help me out?

Thanks,
Ethfun

Hi,

there are some problems,
first of all the full reference to the label is missing
and as a contact can have more than one email both lists contain a list for each contact.

It"s easier to go thru the contacts with two repeat loops


tell application "Address Book"
	set allPeople to every person in group "Email"
	
	repeat with aPerson in allPeople
		repeat with aMail in emails of aPerson
			if value of aMail ends with "edu" then
				set label of contents of aMail to "school"
			end if
		end repeat
	end repeat
	save
end tell


You Are The Man. Thank You!