Skip to content

Instantly share code, notes, and snippets.

@zef
Created December 3, 2010 21:58
Show Gist options
  • Save zef/727627 to your computer and use it in GitHub Desktop.
Save zef/727627 to your computer and use it in GitHub Desktop.
Iterates through Address Book phone numbers so you can change the format programatically.
# Zef Houssney
# http://madebykiwi.com
#
# rb-appscript documentation:
# http://appscript.sourceforge.net/rb-appscript/index.html
#
# Install rb-appscript with:
# sudo gem install rb-appscript
# Make sure to backup your address book before doing this!!!
require "rubygems"
require "action_controller"
require "appscript"
require "osax"
include Appscript
address_book = app('Address Book')
address_book.people.get.each do |person|
puts "\n#{person.name.get}"
person.phones.get.each do |phone|
old_number = phone.value.get.gsub(/\D/, '')
# make your changes here
# documentation for number_to_phone -- http://apidock.com/rails/ActionView/Helpers/NumberHelper/number_to_phone
new_number = ActionController::Base.helpers.number_to_phone(old_number)
# change this and only update certain kinds of numbers that match your criteria
if true
phone.value.set new_number
# Uncomment the following line to actually save your results
# I suggest running it first and previewing the changes to make sure you didn't forget anything.
# phone.save
puts "Changed '#{old_number}' to '#{new_number}'"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment