Skip to content

Instantly share code, notes, and snippets.

@echoz echoz/gist:1426818
Created Dec 3, 2011

Embed
What would you like to do?
Applescript to add a prefix to all phone numbers with checking to see if they are singaporean numbers (8 digits)
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
@echoz

This comment has been minimized.

Copy link
Owner Author

echoz commented Dec 3, 2011

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

@yjsoon

This comment has been minimized.

Copy link

yjsoon commented Dec 12, 2011

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.

@echoz

This comment has been minimized.

Copy link
Owner Author

echoz commented Dec 13, 2011

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
You can’t perform that action at this time.