Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anderscarling/2371823d90fe0d0bfa14e15cf448ce1f to your computer and use it in GitHub Desktop.
Save anderscarling/2371823d90fe0d0bfa14e15cf448ce1f to your computer and use it in GitHub Desktop.
Apple Script for adding country code prefix to numbers in address book that doesn't currently have one
#! /usr/bin/env osascript
on run argv
set is_real to (count of argv > 0 and item 1 of argv equals "--real")
if is_real then
log "Running real run, changes will be saved!"
log ""
else
log "Running test run, add --real to save changes.."
log ""
end if
tell application "Contacts"
set prefix to "+46"
repeat with thePerson in every person
repeat with thePhone in thePerson's every phone
set theNumber to thePhone's value
if (theNumber starts with "0" and theNumber does not start with "00") then
set newNumber to prefix & (get characters 2 thru (get count of characters in theNumber) of theNumber)
log theNumber & " -> " & newNumber
if is_real then
set thePhone's value to newNumber
save thePerson
end if
end if
end repeat
end repeat
end tell
end run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment