Created
April 23, 2016 14:58
-
-
Save anderscarling/2371823d90fe0d0bfa14e15cf448ce1f to your computer and use it in GitHub Desktop.
Apple Script for adding country code prefix to numbers in address book that doesn't currently have one
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
#! /usr/bin/env osascript | |
on run argv | |
set is_real to (count of argv > 0 and item 1 of argv equals "--real") | |
if is_real then | |
log "Running real run, changes will be saved!" | |
log "" | |
else | |
log "Running test run, add --real to save changes.." | |
log "" | |
end if | |
tell application "Contacts" | |
set prefix to "+46" | |
repeat with thePerson in every person | |
repeat with thePhone in thePerson's every phone | |
set theNumber to thePhone's value | |
if (theNumber starts with "0" and theNumber does not start with "00") then | |
set newNumber to prefix & (get characters 2 thru (get count of characters in theNumber) of theNumber) | |
log theNumber & " -> " & newNumber | |
if is_real then | |
set thePhone's value to newNumber | |
save thePerson | |
end if | |
end if | |
end repeat | |
end repeat | |
end tell | |
end run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment