Skip to content

Instantly share code, notes, and snippets.

@shuhei
Created April 17, 2011 02:02
Show Gist options
  • Save shuhei/923679 to your computer and use it in GitHub Desktop.
Save shuhei/923679 to your computer and use it in GitHub Desktop.
Converts phonetic names from Japanese Kana into Roman characters in OSX Address Book. Requires rb-appscript and romankana gems. Make sure to backup your address book before running this.
#!/usr/bin/env ruby
# -*- encoding: utf-8 -*-
require 'romankana'
require 'appscript'
include Appscript
kana_pattern = /^[あ-んア-ヴ]+$/u
class String
def beautify
self.gsub("oo", "oh").gsub("ou", "o").gsub("uu", "u").gsub("si", "shi").capitalize
end
end
book = app('Address Book')
total = book.people.count
(1..total).each do |i|
person = book.people[i].get
first = person.phonetic_first_name.get
last = person.phonetic_last_name.get
if first && first =~ kana_pattern
person.phonetic_first_name.set first.to_roman.beautify
end
if last && last =~ kana_pattern
person.phonetic_last_name.set last.to_roman.beautify
end
end
book.save
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment