Hi,
I changed Jonathan’s code to retrieve the address instead of the email information
First, in Interface Builder connect File’s Owner to will finish launching handler
in the AppleScript file, add this handler
on will finish launching theObject
call method "initABView:" of class "ABHandler" with parameter (view "people_picker" of window "main")
end will finish launching
and replace the else part of the on clicked handler with
else if object_name = "info" then
set the_record to call method "getABDictFromID:picker:" of class "ABHandler" with parameters {the_id, (view "people_picker" of window "main")}
set the_info to {"first name: ", the_record's first_name, return, "last name: ", the_record's last_name, return, "company: ", the_record's company, return, ¬
"street: ", the_record's street, return, "ZIP: ", the_record's zip, return, "city: ", the_record's city}
set contents of text view 1 of scroll view 1 of window "main" to (the_info as Unicode text)
end if
Now replace the contents of the ABHandler.h and ABHandler.m with this code
.h
[code]#import <Cocoa/Cocoa.h>
#import <AddressBook/AddressBook.h>
#import <AddressBook/ABPeoplePickerView.h>
@interface ABHandler : NSObject
- (void)initABView:(ABPeoplePickerView *)picker;
- (NSDictionary *)getABDictFromID:(NSString *)theID picker:(ABPeoplePickerView *)picker;
@end[/code]
.m
[code]#import “ABHandler.h”
NSString *kEmptyString = @“”;
@implementation ABHandler
-
(void)initABView:(ABPeoplePickerView *)picker
{
[picker removeProperty:kABEmailProperty];
[picker addProperty:kABAddressProperty];
[picker setAllowsMultipleSelection:NO];
[picker setValueSelectionBehavior: ABSingleValueSelection];
}
-
(NSDictionary *)getABDictFromID:(NSString *)theID picker:(ABPeoplePickerView *) picker
{
NSString *firstName, *lastName, *company, *city = kEmptyString, *street = kEmptyString, *zip = kEmptyString;
NSDictionary *address;
ABPerson *person = (ABPerson *)[[ABAddressBook sharedAddressBook] recordForUniqueId:theID];
if (person) {
firstName = [person valueForProperty:kABFirstNameProperty];
if (!firstName) firstName = kEmptyString;
lastName = [person valueForProperty:kABLastNameProperty];
if (!lastName) lastName = kEmptyString;
company = [person valueForProperty:kABOrganizationProperty];
if (!company) company = kEmptyString;
NSArray *addresses = [picker selectedValues];
if ([addresses count]) {
address = [addresses objectAtIndex:0];
street = [address objectForKey:@"Street"];
if (!street) street = kEmptyString;
zip = [address objectForKey:@"ZIP"];
if (!zip) zip = kEmptyString;
city = [address objectForKey:@"City"];
if (!city) city = kEmptyString;
}
}
return [NSDictionary dictionaryWithObjectsAndKeys:
firstName, @“first_name”,
lastName, @“last_name”,
company, @“company”,
street, @“street”,
zip, @“zip”,
city, @“city”, nil];
}[/code]