Clean up mobile numbers in Address Book

Oct 03, '03 10:51:00AM

Contributed by: SJT

To cut a long story short, my old phone wasn't very good at filing numbers though it did sync with Address Book. When I upgraded to a Sony Ericsson T610 I needed to clean up the numbers a bit to make sure they were stored nicely on the phone so I wrote this little script.

All it does is go through and internationalise all my mobile numbers and make sure any numbers in the mobile format are labled as mobiles.


set mobileCode to display dialog ¬
 ("Enter the mobile prefix code for your country:") ¬
 default answer "e.g. 07 for the UK"
set mobileCode to text returned of mobileCode
set countryCode to display dialog ¬
 ("Enter the country prefix code for your country:") ¬
 default answer "e.g. +44 for the UK"
set countryCode to text returned of countryCode
set internationalMobile to (countryCode & (character 2 of mobileCode))
tell application "Address Book"
  activate
  set ID_List to (id of people)
  repeat with anID in ID_List
    try
      set phoneList to the phones of person id anID
      repeat with aPhone in phoneList
        set phoneNumber to the value of aPhone as string
        set the_chars to characters 1 thru 4 of phoneNumber as string
        if the_chars is equal to internationalMobile then
          set the label of aPhone to "mobile"
        end if
        set the_chars to characters 1 thru 2 of phoneNumber as string
        if the_chars is equal to mobileCode then
          set interNumber to (countryCode & characters 2 thru ¬
          (the length of phoneNumber) of phoneNumber)
          set the value of aPhone to interNumber
          set the label of aPhone to "mobile"
        end if
      end repeat
    end try
  end repeat
  save addressbook
end tell
Feel free to use and modify as you like, but use the script at your own risk. Be sure to use the Backup Database command in Address Book before you experiment!

Comments (1)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20031001215347512