Re: Address Book: Delete Person
Re: Address Book: Delete Person
- Subject: Re: Address Book: Delete Person
- From: Paul Berkowitz <email@hidden>
- Date: Thu, 15 Jan 2004 11:21:41 -0800
On 1/15/04 10:00 AM, "JimMain" <email@hidden> wrote:
>
I'm trying to delete certain people from the address book. I've deleted
>
groups successfully, but haven't had any luck with people.
>
>
This runs without error, but doesn't delete any entries:
>
>
tell application "Address Book"
>
activate
>
delete (people whose (label of AIM handles) contains "%X")
>
end tell
>
Well, that one doesn't add up. AIM Handles are elements, not properties: you
can have a contact with 2, or 5, or 25 different AIM Handles, and each AIM
Handle might well have a different label. That's why you can only use
'whose' clauses on properties of elements, not elements of elements.
>
I've even tried:
>
>
tell application "Address Book"
>
activate
>
repeat with p in people
>
set l to (get label of AIM Handle of p) as string
You're not specifying _which_ AIM Handle. Many people will have NO AIM
Handles, so this will error. (Many errors in Address Book don't create error
messages, they just waltz on without doing anything. There's a way of
forcing an error.) And otherwise, you either have to specify the first AIM
Handle, if there is one, or do a repeat loop through all of them, if you
want to catch every one, which I think you do.
>
if l contains "%X" then
>
tell p to make new phone at end of phones with properties
>
{label:"delete", value:"delete"}
>
delete p
>
end if
>
end repeat
>
end tell
>
>
It's adding the 'delete' phone so I'm getting true 'if' results, but
>
still not deleting the entries.
It may just be because you're neglecting to 'save addressbook' since you
seem to be catching the first AIM Handle as if it were a property. How about
if you quit Address Book and open it again - are they gone? Anyway, this
should work:
tell application "Address Book"
repeat with p in people
set ll to (get label of every AIM Handle of p)
repeat with i from 1 to (count ll)
set l to item i of ll -- or AIM Handle i of p
if l contains "%X" then
tell p to make new phone at end of phones with properties
{label:"delete", value:"delete"}
delete p -- ??
exit repeat
end if
end repeat -- AIM Handles
end repeat -- people
save addressbook -- !!!
activate
display dialog "Done!"
end tell
--
Paul Berkowitz
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.