Skip to content

Instantly share code, notes, and snippets.

@pedrospdc
Created January 5, 2015 17:42
Show Gist options
  • Save pedrospdc/59193d06c68b709a2397 to your computer and use it in GitHub Desktop.
Save pedrospdc/59193d06c68b709a2397 to your computer and use it in GitHub Desktop.
Moving
on replace_chars(this_text, search_string, replacement_string)
set AppleScript's text item delimiters to the search_string
set the item_list to every text item of this_text
set AppleScript's text item delimiters to the replacement_string
set this_text to the item_list as string
set AppleScript's text item delimiters to ""
return this_text
end replace_chars
tell application "Contacts"
repeat with eachPerson in people
repeat with eachNumber in phones of eachPerson
set theNum to (get value of eachNumber)
if theNum does not start with "+" then
-- log theNum
if theNum does not start with 11 then
set value of eachNumber to "+5511" & theNum
-- log "theNum does not start with 11 +5511" & theNum
else if (theNum does not start with "5" and theNum does not start with "0") then
-- log "+55" & theNum
set value of eachNumber to "+55" & theNum
end if
-- set value of eachNumber to "+55" & theNum
end if
if (theNum starts with "+55" and length of theNum < 12) or (theNum starts with "+559") then
log my replace_chars(theNum, "+55", "+5511")
set value of eachNumber to my replace_chars(theNum, "+55", "+5511")
end if
end repeat
end repeat
save
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment