Hi Brad,
learning Objectve-C is definitively a good idea ;-). Unfortunately ABRecord/ABPerson are not really simple Objects since they can hold many different sub and sub-sub objects (NSDirectories, NSArrays, NSData, NSDate, NSString, NSNumber etc …)
So meanwhile … here’s an other method for you which you could use for searching even without writing any external code - maybe this is already sufficient for your needs?
You can search in any of the existing ABPerson properties (choose one from property record ‘ABProperties’) using one of the comparison methods (choose from property record ‘ABComparisonTypes’).
The result (‘ResultString’) are textual representations of the found ABPersons. Not really an elegant solution maybe - but it could be used to filter the information you need (phone, eMail etc. …).
D.
property ABComparisonTypes : {kABEqual:0, kABNotEqual:1, kABLessThan:2, kABLessThanOrEqual:3, kABGreaterThan:4, kABGreaterThanOrEqual:5, kABEqualCaseInsensitive:6, kABContainsSubString:7, kABContainsSubStringCaseInsensitive:8, kABPrefixMatch:9, kABPrefixMatchCaseInsensitive:10, kABBitsInBitFieldMatch:11, kABDoesNotContainSubString:12, kABDoesNotContainSubStringCaseInsensitive:13, kABNotEqualCaseInsensitive:14, kABSuffixMatch:15, kABSuffixMatchCaseInsensitive:16, kABWithinIntervalAroundToday:17, kABWithinIntervalAroundTodayYearless:18, kABNotWithinIntervalAroundToday:19, kABNotWithinIntervalAroundTodayYearless:20, kABWithinIntervalFromToday:21, kABWithinIntervalFromTodayYearless:22, kABNotWithinIntervalFromToday:23, kABNotWithinIntervalFromTodayYearless:24}
property ABProperties : {kABFirstNameProperty:"First", kABLastNameProperty:"Last", kABFirstNamePhoneticProperty:"FirstPhonetic", kABLastNamePhoneticProperty:"LastPhonetic", kABBirthdayProperty:"Birthday", kABOrganizationProperty:"Organization", kABJobTitleProperty:"JobTitle", kABHomePageProperty:"HomePage", kABURLsProperty:"URLs", kABEmailProperty:"Email", kABAddressProperty:"Address", kABPhoneProperty:"Phone", kABAIMInstantProperty:"AIMInstant", kABJabberInstantProperty:"JabberInstant", kABMSNInstantProperty:"MSNInstant", kABYahooInstantProperty:"YahooInstant", kABICQInstantProperty:"ICQInstant", kABNoteProperty:"Note", kABMiddleNameProperty:"Middle", kABMiddleNamePhoneticProperty:"MiddlePhonetic", kABTitleProperty:"Title", kABSuffixProperty:"Suffix", kABNicknameProperty:"Nickname", kABMaidenNameProperty:"MaidenName", kABOtherDatesProperty:"ABDate", kABRelatedNamesProperty:"ABRelatedNames", kABDepartmentProperty:"ABDepartment", kABPersonFlags:"ABPersonFlags"}
on clicked theObject
set searchString to contents of text field "search" of window "main"
set AB to (call method "sharedAddressBook" of class "ABAddressBook")
set theSearch to (call method "searchElementForProperty:label:key:value:comparison:" of class "ABPerson" with parameters {(kABLastNameProperty of ABProperties), null, null, searchString, (kABEqual of ABComparisonTypes)})
set searchResults to (call method "recordsMatchingSearchElement:" of AB with parameter theSearch)
set ResultCount to (count of searchResults)
if (ResultCount > 0) then
repeat with i from 1 to ResultCount
set ResultString to (call method "description" of (item i of searchResults))
log ResultString
end repeat
end if
end clicked