MacOS Apple Script: Add +1 (country code) to all US Contacts
heylo,
i am posting this to help anyone who wants to add a country code to a bunch of contacts.
i recently moved to Germany and upgraded to a M1 Mac Mini with Ventura installed. whenever i would receive text messages from US friends, sometimes their contact info (name) would not show up properly. the received numbers in Messages would start with +1. i figured out that since most of my contacts are from the US, their contact info was missing the +1 before the number since in the US that is not needed to dial a number. and hence, Messages did not equate +1 212 555 1212 with 212 555 1212.
i found an Apple Script on this forum that was broken, but i was able to fix it. below are instructions on how to use this script and add +1 to your US contacts.
1) in MacOS, open Contacts
2) back up your contacts! go to File > Export > Export Contacts Archive
3) open Script Editor
4) copy and paste the script below into the editor
5) compile the script by clicking on the hammer symbol in the top right of the editor window
6) then run the script by clicking on the play looking symbol to the left of the hammer
it will take a few minutes to go through all of your contacts. this will add a "+1" to all of your contacts that don't already have a "+", "1" or "0" at the beginning of the number.
i hope this helps someone! enjoy!
copy and paste script below this line:
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 "1" and theNum does not start with "0") then set value of eachNumber to "+1" & theNum
end repeat
end repeat
save
end tell
BP mini