Alter email addresses in Address Book

Hello,

I have a script I’ve been trying to write, but I keep hitting a wall when I get to someone with multiple email addresses.

Basically, my school is changing our domain name from @school.edu to @mail.school.edu and I would like a quick and easy way to parse through my entire book, make the changes as necessary and leave every other bit of info just as I found it.

Would anyone be so kind as to help?

thanks!
dennis

Hi filmsmith,

The following AppleScript code should do the trick and save you from drudgery. Please make a backup of your database prior to using this script. If something goes wrong, you will be happy to have a working copy of your address book data :slight_smile:


tell application "Address Book"
	set allcontacts to every person
	repeat with contact in allcontacts
		set allmailobj to every email of contact
		repeat with mailobj in allmailobj
			set mailaddress to value of mailobj
			if mailaddress ends with "@school.edu" then
				set offsetatsign to offset of "@" in mailaddress
				set firstpart to (characters 1 through (offsetatsign - 1) of mailaddress) as Unicode text
				set newmailaddress to firstpart & "@mail.school.edu"
				set value of mailobj to newmailaddress
			end if
		end repeat
	end repeat
	save addressbook
end tell

Fantastic! Thanks, Martin. That did the trick perfectly. I’ll be hanging onto that Address Book backup just in case I notice any irregularities, but at a quick glance, everything looks fine.

Again, thanks!
dennis