Anyone have recommendations for how to do this nicely? I thought about creating vCards and merging them somehow, but none of the CPAN vCard modules seem to actually be able to create them. Also, I'm not exactly clear on how I'd do the merge anyway. Is there some way to tap into iSync or something?
You can access AddressBook with PerlObjCBridge.
perldoc PerlObjCBridge http://developer.apple.com/documentation/UserExperience/Reference/AddressBook/ObjC_classic/index.html
Here is a example of inserting a person.
#!/usr/bin/perl
package ABAddressBook; our @ISA = qw(PerlObjCBridge);
package ABMutableMultiValue; our @ISA = qw(PerlObjCBridge);
package ABPerson; our @ISA = qw(PerlObjCBridge);
package main;
use strict; use warnings; use Foundation;
# Load AddressBook framework
my $bundle = '/System/Library/Frameworks/AddressBook.framework'; my $framework = NSBundle->alloc->initWithPath_( $bundle );
$framework->load() or die("Failed to load: $bundle");
# Constants sub kABFirstNameProperty { 'First' } sub kABLastNameProperty { 'Last' } sub kABNicknameProperty { 'Nickname' } sub kABMaidenNameProperty { 'MaidenName' } sub kABBirthdayProperty { 'Birthday' } sub kABOrganizationProperty { 'Organization' } sub kABJobTitleProperty { 'JobTitle' } sub kABHomePageProperty { 'HomePage' } sub kABEmailProperty { 'Email' } sub kABAddressProperty { 'Address' } sub kABAddressCityKey { 'City' } sub kABAddressCountryCodeKey { 'CountryCode' } sub kABAddressCountryKey { 'Country' } sub kABAddressStateKey { 'State' } sub kABAddressStreetKey { 'Street' } sub kABAddressZIPKey { 'ZIP' } sub kABPhoneProperty { 'Phone' } sub kABPhoneMobileLabel { '_$!<Mobile>!$_' } sub kABPhoneMainLabel { '_$!<Main>!$_' } sub kABPhoneHomeFAXLabel { '_$!<HomeFAX>!$_' } sub kABPhoneWorkFAXLabel { '_$!<WorkFAX>!$_' } sub kABPhonePagerLabel { '_$!<Pager>!$_' } sub kABWorkLabel { '_$!<Work>!$_' } sub kABHomeLabel { '_$!<Home>!$_' } sub kABOtherLabel { '_$!<Other>!$_' }
my $book = ABAddressBook->sharedAddressBook;
my $person = ABPerson->alloc->init; my $phone = ABMutableMultiValue->alloc->init; my $email = ABMutableMultiValue->alloc->init; my $address = ABMutableMultiValue->alloc->init;
$person->setValue_forProperty_( 'Christian', kABFirstNameProperty ); $person->setValue_forProperty_( 'Hansen', kABLastNameProperty );
$email->addValue_withLabel_( '[EMAIL PROTECTED]', kABWorkLabel ); $person->setValue_forProperty_( $email, kABEmailProperty );
$phone->addValue_withLabel_( '+46 40 660 17 50', kABWorkLabel ); $phone->addValue_withLabel_( '+46 708 42 88 83', kABPhoneMobileLabel ); $person->setValue_forProperty_( $phone, kABPhoneProperty );
my $dictionary = NSMutableDictionary->dictionaryWithCapacity_(6); $dictionary->setObject_forKey_( 'Norregatan 18', kABAddressStreetKey ); $dictionary->setObject_forKey_( 'Malmoe', kABAddressCityKey ); $dictionary->setObject_forKey_( '21127', kABAddressZIPKey ); $dictionary->setObject_forKey_( 'Sweden', kABAddressCountryKey ); $dictionary->setObject_forKey_( 'se', kABAddressCountryCodeKey ); $address->addValue_withLabel_( $dictionary, kABWorkLabel );
$person->setValue_forProperty_( $address, kABAddressProperty );
$book->addRecord_( $person );
if ( $book->hasUnsavedChanges ) { $book->save; }
--
Hansen