我一直在尝试使用 python 和 pyObjC 将“工作”和“家庭”电话号码添加到 Mac 地址簿。我相信您需要添加一个多值对象,但我不确定如何使用 pyobjc 来执行此操作。这是到目前为止我整理的代码示例:
import AddressBook
from AddressBook import *
ab = AddressBook.ABAddressBook.sharedAddressBook()
p = ABPerson.alloc().init()
p.setValue_forProperty_('JOE', kABFirstNameProperty)
p.setValue_forProperty_('TEST', kABLastNameProperty)
homephoneNumberMultiValue = ABMultiValueCreateMutable()
homephoneNumberMultiValue = ABMultiValueAddValueAndLabel(homephoneNumberMultiValue, '555-555-1212', kABPersonPhoneMobileLabel);
p.setValue_(kABPersonPhoneProperty, homephoneNumberMultiValue);
workphoneNumberMultiValue = ABMultiValueCreateMutable()
workphoneNumberMultiValue = ABMultiValueAddValueAndLabel(workphoneNumberMultiValue, '555-555-1213', kABPersonWorkMobileLabel);
p.setValue_(kABPersonPhoneProperty, workphoneNumberMultiValue);
ab.addRecord_(p)
ret = ab.save()