Can you give me an example of the phone number string such as:
(041) 123456
+041 123456
I could search for 041 and replace all, but it would replace any 041 in the main number, also. So, I need to know how the number is formatted to write the replacement code correctly. If the first three characters are just 041, that's pretty easy:
property oldPrefix : "041"
property newPrefix : "015"
tell application "Contacts"
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 characters 1 thru 3 of theNumber = characters of oldPrefix then
try
set newNumber to my replace_chars(theNumber, oldPrefix, newPrefix)
set value of aPhoneNumber to newNumber
on error
copy name of aPerson to end of errorList
end try
end if
end repeat
if errorList is not {} then
display dialog "Couldn't change: " & items of errorList
end if
end if
end repeat
save
end tell
on replace_chars(this_text, search_string, replacement_string)
set AppleScript's text item delimiters to the search_string
set the item_list to every text item of this_text
set AppleScript's text item delimiters to the replacement_string
set this_text to the item_list as string
set AppleScript's text item delimiters to ""
return this_text
end replace_chars