Created
November 3, 2011 14:47
-
-
Save cyfdecyf/1336682 to your computer and use it in GitHub Desktop.
Using MacRuby to operate the Address Book contacts
This file contains 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/env ruby | |
# For contacts which have only the first name, move the first name to last name | |
framework 'AddressBook' | |
def move_first2last(person) | |
first = person.valueForProperty(KABFirstNameProperty) | |
last = person.valueForProperty(KABLastNameProperty) | |
if last == nil | |
#p first, last | |
person.setValue(nil, forProperty: KABFirstNameProperty) | |
person.setValue(first, forProperty: KABLastNameProperty) | |
end | |
end | |
ab = ABAddressBook.addressBook | |
ab.people.each do |person| | |
move_first2last(person) | |
end | |
ab.save |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment