Applescript and Address Book

Hello, I have a question about how to use AppleScript to make bulk modifications to my Address Book. I am trying to find all phone numbers that are labeled as the person’s “main” phone number, and change it to “other”. This is because my phone does not sync entries under “main”.

After googling a bunch of sites, I came up with the following code:tell application "Address Book" set thePeople to every person whose first name = "Andy" repeat with thePerson in thePeople set thePhones to phones of thePerson repeat with thePhone in thePhones set theLabel to (label of thePhone) set theLastName to last name of thePerson display dialog theLastName & " " & theLabel if theLabel = "main" then set (label of thePhone) to "other" end if end repeat end repeat end tell
When I run the script, it gives me three dialogs: “Jackson work”, “Hu main”, and “Long main”. I run it a second time, and it says: “Jackson work”, “Hu other”, “Long other”. It looks like it’s worked!

However, if I look at the entries in Address Book, they have not changed. Furthermore, if I quit and reopen Address Book and run the script again, it goes back to saying “main” the first time and then “other” all subsequent times.

Anyone know what’s up?

Model: MacBook Pro core 2 duo
Browser: Safari 534.52.7
Operating System: Mac OS X (10.7)

Hi,

since 10.6 you have to save the address book explicitly in the script.
Just add a save line at the end


.
		end repeat
	end repeat
	save
end tell

Thanks, that worked perfectly!

How would this script need to be modified to make the change for everyone in the address book rather than inserting one contact name at a time, i.e. “Andy”

omit “whose first name = “Andy””

That did it.

One last question. How do you make it make all the changes without prompting you to accept each one that it finds?

delete or comment out the display dialog line