LEFTEROS / PERSONAL NOTES
Mass-edit Address Book with Automator
28 March 2011 / Lefteris Iliadis / SomniusX
Historical text from HellasProject (2009–2014). It is not current advice or a present-day service.
One of the few drawbacks of Address Book on Mac OS X is the lack of a way to change contacts in bulk. A few lines of code in Automator can change that.
First open Script Editor (Applications → AppleScript or Applications → Utilities, depending on the OS X version). Paste the code below and press Compile. You should not hit a problem.
tell application "Address Book"
set peopleToChange to people whose (street of first address) contains "321 Old Street"
repeat with thePerson in peopleToChange
set (street of first address) of thePerson to "123 New Street"
end repeat save end tell
The big advantage of AppleScript is that you do not need programming knowledge to use it. Here is what the script does.
The first line means we are going to “tell” something to Address Book. The second finds every contact whose first address street contains “321 Old Street” and stores them as “peopleToChange”. The third says we will walk that list and call each item “thePerson”. The fourth changes that person’s first-address street to “123 New Street”. The fifth ends the loop, the sixth saves, and the last ends talking to Address Book.
You should write your own AppleScript for your needs. This is an example so you see how it works and how easy it is to adapt. When you are done, press Run to apply the changes.
Below are a few other scripts that may help or make the process clearer.
Change every phone “020 6704 3205” to “020 1523 6843”.
tell application "Address Book"
repeat with i from 1 to (count every person)
set phoneProperties to properties of phones of person i
repeat with j from 1 to (count of phoneProperties)
if value of item j of phoneProperties contains "020 6704 3205" then
set value of item j of phones of person i to "020 1523 6843"
end if end repeat end repeat save end tell
Change “@googlemail.com” in emails to “@gmail.com”
tell application "Address Book" repeat with i from 1 to (count every person)
set theEmailAddresses to properties of emails of person i
repeat with j from 1 to (count of theEmailAddresses)
if value of item j of theEmailAddresses contains "@googlemail.com" then
set oldAddress to value of item j of theEmailAddresses
set AppleScript's text item delimiters to {"@"}
set firstBit to first text item of oldAddress
set newAddress to firstBit & "@gmail.com"
set value of item j of emails of person i to newAddress
end if end repeat end repeat save end tell
Source: tutz.gr