Created
August 25, 2009 21:02
-
-
Save julik/175026 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
$KCODE = 'u' | |
require 'osx/cocoa' | |
OSX.require_framework "AddressBook" | |
# The SuperDeTussenvoegselizator. On the iPhone, | |
# names starting with "van " will sort in the V, thus the half of | |
# your contacts will be on one letter and looking vor "de Jong" | |
# will have you on "D" instead. Use the SuperDetussenvoegselizer(tm) | |
# to stash your Tussenvoegsels in the "middleName" field | |
# ACHTUNG!!!! Make a backup of your AB before running this | |
VOEGSELZ = [ | |
"van der", "von", "ter", "van", "van de", "van de(n|r?)", "de", "du", "ten" | |
].sort{|a, b| a.length <=> b.length }.reverse.join("|") | |
PREFIX_PATTERN = /^(#{VOEGSELZ})\s+/i | |
def process_record(ab_person) | |
first = ab_person.valueForProperty("firstName").to_s | |
mid = ab_person.valueForProperty("middleName").to_s | |
last = ab_person.valueForProperty("lastName").to_s | |
if last =~ PREFIX_PATTERN | |
dutchism = $1 | |
last.gsub!(PREFIX_PATTERN, '') | |
middle = "#{middle} #{dutchism.downcase}".strip | |
print "." | |
ab_person.setValue_forProperty(first, "firstName") | |
ab_person.setValue_forProperty(middle, "middleName") | |
ab_person.setValue_forProperty(last, "lastName") | |
end | |
end | |
book = OSX::ABAddressBook.sharedAddressBook | |
book.people.each do | ab_person | | |
process_record(ab_person) | |
$stdout.flush | |
end | |
# will take a LOOOONG time | |
book.save if book.hasUnsavedChanges | |
puts "Tussenvoegsels cheinged, now go away or I will taunt you anoser taime!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment