Created
October 25, 2019 21:08
-
-
Save sbenario/97449bc04919d3027dfe9cdc54d74ca5 to your computer and use it in GitHub Desktop.
AppleScript program to iterate through contacts and add a country code to all phone numbers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- wholeheartedly taken from: https://gist.github.com/mzcu/3771916 | |
-- my first applescript anything | |
-- I had too many contacts to do them all at once (kept hanging or doing something wrong, who knows), so I did letter by letter. | |
tell application "Contacts" | |
-- tell application "Contacts" to set thisPerson to person "John Doe" | |
set peopleToChange to people whose last name starts with "Z" | |
log "count of people results in the query is: " & number of items in peopleToChange | |
repeat with thisPerson in peopleToChange | |
-- log "person name: " & (first name of thisPerson) & (last name of thisPerson) | |
repeat with eachNumber in phones of thisPerson | |
set theOrigNum to (get value of eachNumber) | |
if (theOrigNum does not start with "+" and theOrigNum does not start with "0" and theOrigNum does not start with "1") then | |
log (first name of thisPerson) & " " & (last name of thisPerson) & " orig number " & theOrigNum | |
set value of eachNumber to "+1" & theOrigNum | |
log " changing to " & value of eachNumber | |
-- delay 1 | |
end if | |
-- there must be a nicer way to do this, but i'm lazy. I dont' think anything will hit both if statements | |
if (theOrigNum does not start with "+" and theOrigNum does not start with "0" and theOrigNum starts with "1") then | |
log (first name of thisPerson) & " " & (last name of thisPerson) & " orig number " & theOrigNum | |
set value of eachNumber to "+" & theOrigNum | |
log " changing to " & value of eachNumber | |
-- delay 1 | |
end if | |
end repeat | |
end repeat | |
delay 15 -- here's your option to bail out if you see anything weird while reading logs | |
save | |
end tell |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment