Created
December 3, 2011 10:45
-
-
Save echoz/1426818 to your computer and use it in GitHub Desktop.
Applescript to add a prefix to all phone numbers with checking to see if they are singaporean numbers (8 digits)
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
tell application "Address Book" | |
set prefix to "+65" | |
repeat with p in (get people) | |
repeat with n in (get p's phones) | |
set num to ReplaceText(n's value, " ", "") of me | |
if (count num) is 8 then | |
set n's value to prefix & num | |
end if | |
end repeat | |
save p | |
end repeat | |
save | |
end tell | |
on ReplaceText(theString, fString, rString) | |
set current_Delimiters to text item delimiters of AppleScript | |
set AppleScript's text item delimiters to fString | |
set sList to every text item of theString | |
set AppleScript's text item delimiters to rString | |
set newString to sList as string | |
set AppleScript's text item delimiters to current_Delimiters | |
return newString | |
end ReplaceText |
Works as advertised. Thanks! Only suggestion would be to log whose card has been changed, so the user can keep track of it in case anything goes wrong.
as they say... always backup before you make changes. :P
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
added replacement of text function from somewhere to remove spaces in the phone number field.