develooper Front page | perl.macosx | Postings from April 2004

Re: Merging into Address Book

Thread Previous | Thread Next
From:
rick
Date:
April 21, 2004 17:45
Subject:
Re: Merging into Address Book
On Tue, Apr 20, 2004 at 10:50:01PM -0500, Ken Williams wrote:

> Say, I built the Address_Book glue and looked through its docs, but I 
> don't see methods to search the database for entries that have certain 
> properties.  Do you know of any way to use the "Find" functionality, or 
> specify required properties, using the applescript/glue interface?

Here's the script I use for querying my addressbook from mutt.
The output format is specific to the mutt interface,
but the commented out section shows how to get the address info.

rick
---- cut here ---
#!/usr/local/bin/perl
use Mac::Glue qw(:glue);
use Mac::Apps::Launch;

my $glue=Mac::Glue->new('Address Book',bundle=>'com.apple.AddressBook');
my $id=$glue->{ID};
if(!IsRunning($id)) {
    LaunchApps($glue->{ID}) or die $^E;
    $glue->close($glue->prop('window')) or warn $^E;
}

my $q=shift;
print "Querying AddressBook...\n";
my @people=$glue->obj('people')->get;
foreach my $entry (@people) {
    my @emails=$entry->prop('email')->get;
    next unless @emails;

    foreach my $email (@emails) {
	my $addr=$email->prop('value')->get;
	my $name=$entry->prop('name')->get;
	print "$addr\t$name\t",$email->prop('label')->get,"\n"
	    if $name =~ /$q/ || $addr =~ /$q/;
    }
#    my($addr)=$entry->prop('address')->get;
#    next unless $addr;
#    print $addr->prop('street')->get,"\n";
#    print $addr->prop('city')->get," ";
#    print $addr->prop('state')->get," ";
#    print $addr->prop('zip')->get,"\n";
}
exit 0;

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About