Skip to content

Instantly share code, notes, and snippets.

@cpinto
Created May 25, 2017 12:13
Show Gist options
  • Save cpinto/f975ef45243b5814dea493dbb93cf104 to your computer and use it in GitHub Desktop.
Save cpinto/f975ef45243b5814dea493dbb93cf104 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