Created
September 23, 2012 15:01
-
-
Save mzcu/3771916 to your computer and use it in GitHub Desktop.
Add country code to OS X Address book entries
This file contains hidden or 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
(* | |
AddCountryCode.scpt | |
===================== | |
Customization of Andreas Amann's script posted on https://discussions.apple.com/message/9169756#9169756 | |
Description | |
------------ | |
Adds RS country code prefix (+381) to all phonebook entries with leading zero (RS local number format): 063123456 -> +38163123456 | |
Back up your Address book before running this script, your mileage may vary!!! | |
Usage | |
------ | |
Paste to AppleScript Editor and click "Run". | |
*) | |
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 "381" and theNum starts with "0") then | |
-- log "+381" & (get text 2 thru (length of theNum) of theNum) | |
set value of eachNumber to "+381" & (get text 2 thru (length of theNum) of theNum) | |
end if | |
end repeat | |
end repeat | |
save | |
end tell |
@bluestarstudios Great update! I made a couple small changes to add a little more information to logging and allow for dry runs: https://gist.github.com/nquinlan/7d4b5716eb0644dac0af3b97dfc7cc54
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here's an updated version for USA, Canada, and other North American phone numbers. It checks the format and prepends the number with a "+1" where applicable. It also logs what was processed, which phone numbers were already correct with a country code, and which ones were skipped. The log files are saved to the desktop.
As always, make a backup first and modify the file as needed. Test first before using it to make sure it's applying to your use case correctly.