Skip to content

Instantly share code, notes, and snippets.

@cyfdecyf
Created November 3, 2011 14:47
Show Gist options
  • Save cyfdecyf/1336682 to your computer and use it in GitHub Desktop.
Save cyfdecyf/1336682 to your computer and use it in GitHub Desktop.
Using MacRuby to operate the Address Book contacts
#!/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