Does anybody know of a good example of using people picker in ApplescriptOBJc?
I used this once in Applescript studio but I have no idea how to do this now?
Does anybody know of a good example of using people picker in ApplescriptOBJc?
I used this once in Applescript studio but I have no idea how to do this now?
What is it that you want to do? I haven’t seen any examples, but it certainly can be used in ASOC. You can set up the view in IB, but remember to add the Address Book framework to your project to use it.
Ric
I created a couple of little apps that show how to use ABAddressBook and ABPeoplePickerView in ASOC. The first example logs the name and address of the person in the selected row of the people picker.
script AddressBookAppDelegate
property parent : class "NSObject"
property ppv : missing value -- IBOutlet for an ABPeoplePickerView
on applicationWillFinishLaunching_(aNotification)
set noter to current application's NSNotificationCenter's defaultCenter()
noter's addObserver_selector_name_object_(me, "watch:", current application's ABPeoplePickerValueSelectionDidChangeNotification, ppv)
end applicationWillFinishLaunching_
on Watch_(aNote)
set firstRecord to ppv's selectedRecords's objectAtIndex_(0) -- firstRecord is an ABPerson
set fFirst to firstRecord's valueForProperty_("First")
set fLast to firstRecord's valueForProperty_("Last")
set multiValue to firstRecord's valueForProperty_("Address") -- multiValue is an ABMultiValueCoreDataWrapper
if multiValue is not missing value then
set dict to multiValue's valueAtIndex_(0) -- objectAtindex doesn't work with an ABMultiValueCoreDataWrapper
set fStreet to dict's valueForKey_("Street")
set fCity to dict's valueForKey_("City")
set fState to dict's valueForKey_("State")
set fZip to dict's valueForKey_("ZIP")
set fString to current application's NSString's stringWithFormat_("%@ %@ %@ %@, %@ %@", fFirst, fLast, fStreet, fCity, fState, fZip)
log fString
else
log "No Address For This Record Was Found"
end if
end Watch_
end script
This second example shows how to search ABAddressBook in code without any interface. I have 2 different search criteria (one commented out) that both found me in my address book. You should look at the docs for the method, searchElementForProperty:label:key:value:comparison: to see all its possibilities. In both of these apps, I’ve shortened some of the property names – for instance in the code below I use “Last” in the defining “find” instead of “current application’s kABLastNameProperty” just to make the code shorter. I logged “current application’s kABLastNameProperty” to find out that it is equal to the string “Last”.
on applicationWillFinishLaunching_(aNotification)
set ab to current application's ABAddressBook's sharedAddressBook()
--set find to current application's ABPerson's searchElementForProperty_label_key_value_comparison_("Address", ¬
--current application's kABAddressHomeLabel, "City", "Sebastopol", current application's kABEqual)
set find to current application's ABPerson's searchElementForProperty_label_key_value_comparison_("Last", ¬
missing value, missing value, "DelMar", current application's kABEqual)
set results to ab's recordsMatchingSearchElement_(find) -- results is an NSArray
if results's |count|() as integer is not 0 then
set firstRecord to results's objectAtIndex_(0) -- firstRecord is an ABPerson
set fFirst to firstRecord's valueForProperty_("First")
set fLast to firstRecord's valueForProperty_("Last")
set multiValue to firstRecord's valueForProperty_("Address") -- multiValue is an ABMultiValueCoreDataWrapper
set dict to multiValue's valueAtIndex_(0) -- objectAtindex doesn't work with an ABMultiValueCoreDataWrapper
set fStreet to dict's valueForKey_("Street")
set fCity to dict's valueForKey_("City")
set fState to dict's valueForKey_("State")
set fZip to dict's valueForKey_("ZIP")
set fString to current application's NSString's stringWithFormat_("%@ %@ %@ %@, %@ %@", fFirst, fLast, fStreet, fCity, fState, fZip)
log fString
else
log "No Matching Record Was Found"
end if
end applicationWillFinishLaunching_
end script
Ric