Adding (+1) to US tel numbers in Address Book (Mac OS X)

This is my memo to share with everyone.

I moved to Japan, and needed to add +1 to all my US contacts. Then I found the following post

Adding 1 to all phone numbers in address book
https://discussions.apple.com/message/9169756

However, I already have many Japanese phone numbers in my address book starting with “0” So I’ve modified Andreas’ code to the folliowing

tell application "Address Book"
repeat with eachPerson in people
repeat with eachNumber in phones of eachPerson
set theNum to (get value of eachNumber)
if (theNum does not start with "+" and theNum does not start with "1" and theNum does not start with "0") then
set value of eachNumber to "+1" & theNum
end if
end repeat
end repeat
save
end tell

So that it will skip the phone number starting with zero (0).

How to use the code

  • Launch AppleScript Editor
  • Copy and paste the above codes
  • Click [Compile]
  • Run the script (CAUTION)

If you have more than 300 contacts, you need the following extra step. Otherwise, the script may freeze (like it did it on me)

  • After clicking [Compile]
  • Save it onto [Library] – [Scripts] – [Address Book Scripts]
  • Go to Preferences of AppleScript Editor
  • In General, make sure “Show Script menu in menu bar” is checked
  • You will see “S” like curve on the menu bar on top
  • Launch Address Book
  • Go to script menu – AddressBook Scripts – [your script]
  • Then it will run without any notification
  • I had 1500 contacts, and it took me about 5 min

Done.

I had to include the script in the menu.

If I run the script in Script Editor, it always freezes at 380 items.

Other useful post

Need to add area code to all local contacts’ phone numbers
https://discussions.apple.com/message/10833980

  • Bob C

    Thanks! However, when I click “compile” a Syntax error comes up “Expected end of line but found unknown token” and the “;” on line 06 is highlighted. 

    Any suggestions? 

    I’m running Lion 10.7.4. 

    • Oops. Thank you Bob!
      When I pasted onto WordPress, they converted “&” to “&” for HTML safe purpose on Line 6.

      Sorry about that. The code is not being fixed.

  • Brian Topping

    Thanks, this is great. I’ve got a lot of programming experience and so little with AppleScript. I got to an extended travel destination and all my contacts from the US started showing up as phone numbers on my phone. This was caused by the phone correctly recognizing that it was in a different country and the messages from the US should be prefixed with a “+1”. After the script finished, my contacts updated rather instantaneously over iCloud and the phone started displaying properly.

    I would offer that users should back up their contacts before running the script. No reason not to when doing something this important.

    • Thanks, Brian!
      Sometime Apple does too much!