Skip to content

Instantly share code, notes, and snippets.

@echoz
Created December 3, 2011 10:45
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
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)
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
Copy link
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