Re: Parsing phone/emails in Address Book
Re: Parsing phone/emails in Address Book
- Subject: Re: Parsing phone/emails in Address Book
- From: Andrew Oliver <email@hidden>
- Date: Fri, 07 Mar 2003 20:10:05 -0800
Hmm.. Interesting problem, compounded by the fact that a person can have
multiple phone numbers.
My initial guess was "value of every phone of every person" which almost
works, except that it returns a list of phones for every person, so you'd
still have to iterate through the phone lists.
set phoneList to {}
Set emailList to {}
tell application "Address Book"
-- loop through all the people
repeat with aPerson in every person
-- get the phone numbers
repeat with aPhone in (every phone of aPerson)
copy value of aPhone to end of phoneList
end repeat
-- get the email addresses
repeat with anEmail in (every email of aPerson)
copy value of anEmail to end of emailList
end repeat
end repeat
end tell
As for the major differences, there's no need to explicitly refer to
references to lists. You can just point to them directly, and AppleScript
works out the details. FWIW, I can't think of a single script I've ever
written that's used a reference to an object rather than directly using the
object itself - that should give you an idea of how often you need to use
references. They have their uses, but are the exception rather than the
rule.
Secondly, AppleScript's loop iteration routines are very handy. Using the
structure:
repeat with aValue in someList
...
end repeat
AppleScript will iterate through someList, setting the variable 'aValue' to
each subsequent item in the list. Very handy.
Andrew
:)
On 3/7/03 7:31 PM, "Darwin Zins" <email@hidden> wrote:
>
I am new to applescript and I was wondering if there is a
>
better/preferred/less verbose way to do this:
>
>
tell application "Address Book"
>
set peopleCount to the count of people
>
end tell
>
>
repeat with i from 1 to the peopleCount
>
tell application "Address Book"
>
tell person i
>
>
set a_phones to {}
>
set phoneRef to (a reference to a_phones)
>
set phoneCount to the count of phones
>
set existingPhones to (every phone)
>
repeat with j from 1 to the phoneCount
>
set currentItem to item j of existingPhones
>
copy value of currentItem to the end of phoneRef
>
end repeat
>
>
set a_emails to {}
>
set emailRef to (a reference to a_emails)
>
set emailCount to the count of emails
>
set existingEmails to (every email)
>
repeat with j from 1 to the emailCount
>
set currentItem to item j of existingEmails
>
copy value of currentItem to the end of emailRef
>
end repeat
>
>
Any comments or suggestions?
>
>
All I'm trying to do is copy the values of the phone numbers and email
>
addresses to a list, seems like a lot of code.
>
>
Thank you
>
_______________________________________________
>
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.
_______________________________________________
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.