Need to add area code to all local contacts' phone numbers
Thanks in advance.
MacBook Pro, iPhone 16GB, Mac OS X (10.4.7)
You can make a difference in the Apple Support Community!
When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.
When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.
MacBook Pro, iPhone 16GB, Mac OS X (10.4.7)
property myAreaCode : "(505) "
tell application "Address Book"
repeat with aPerson in people
set thePhones to phones of aPerson
if thePhones is not {} then
set errorList to {}
repeat with aPhoneNumber in thePhones
set theNumber to value of aPhoneNumber
if length of (theNumber) is less than 10 then
try
set value of aPhoneNumber to myAreaCode & value of aPhoneNumber
on error
copy name of aPerson to end of errorList
end try
end if
end repeat
if errorList is not {} then
display dialog errorList
end if
end if
end repeat
save
end tell
Change the myAreaCode property to reflect your area code and the format you want (the part inside the quotes). E.g. if you want to use dashes as separators, put "505-" inside the quotes.
property myAreaCode : "+31 "
tell application "Address Book"
repeat with aPerson in people
set thePhones to phones of aPerson
if thePhones is not {} then
set errorList to {}
repeat with aPhoneNumber in thePhones
set theNumber to value of aPhoneNumber
if theNumber begins with "0" then
try
set value of aPhoneNumber to myAreaCode & (characters 2 thru (number of characters of theNumber) of theNumber)
on error
copy name of aPerson to end of errorList
end try
end if
end repeat
if errorList is not {} then
display dialog errorList
end if
end if
end repeat
save
end tell
tell application "Address Book"
set errorList to {}
repeat with aPerson in people
set USAddress to false
repeat with anAddress in addresses of aPerson
if country code of anAddress is "us" then set USAddress to true
end repeat
if USAddress is true then
set thePhones to phones of aPerson
if thePhones is not {} then
repeat with aPhoneNumber in thePhones
set theNumber to value of aPhoneNumber
if length of theNumber is 10 then
try
set value of aPhoneNumber to 1 & theNumber
on error
copy name of aPerson to end of errorList
end try
end if
end repeat
end if
end if
end repeat
if errorList is not {} then
display dialog "Change failed for " & errorList
end if
save
end tell
I did limited testing on this, but it seemed to work. Before running it, you should export your addresses to an Address Book Archive (File Menu). If you need to recover them, you just have to double-click the address book archive.Need to add area code to all local contacts' phone numbers