Skip to content

Instantly share code, notes, and snippets.

@cpinto
Created May 25, 2017 12:13
Show Gist options
  • Save cpinto/4298866c5ff9f499f5c8ea2d31dae3e6 to your computer and use it in GitHub Desktop.
Save cpinto/4298866c5ff9f499f5c8ea2d31dae3e6 to your computer and use it in GitHub Desktop.
This here script fixes phone numbers in Mac contacts to include international prefixes. Good when you move elsewhere.
on findAndReplaceInText(theText, theSearchString, theReplacementString)
set AppleScript's text item delimiters to theSearchString
set theTextItems to every text item of theText
set AppleScript's text item delimiters to theReplacementString
set theText to theTextItems as string
set AppleScript's text item delimiters to ""
return theText
end findAndReplaceInText
tell application "Contacts"
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 "00" and theNum does not start with "44" and theNum starts with "0") then
set thePhoneNumber to (get text 2 thru (length of theNum) of theNum)
set nmbr to my findAndReplaceInText(thePhoneNumber, " ", "")
--log "+44" & nmbr
set value of eachNumber to "+44" & nmbr
end if
end repeat
end repeat
save
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment