Applescript to add a prefix to all phone numbers with checking to see if they are singaporean numbers (8 digits)

  • Download Gist
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
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
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

added replacement of text function from somewhere to remove spaces in the phone number field.

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

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.