Re: birth date from Address Book
Re: birth date from Address Book
- Subject: Re: birth date from Address Book
- From: Paul Berkowitz <email@hidden>
- Date: Wed, 12 Mar 2003 10:41:47 -0800
On 3/12/03 9:26 AM, "Darwin Zins" <email@hidden> wrote:
>
I am finding that going through the address book is excruciatingly
>
slow. Would using properties speed this up?
Yes. a lot.
>
When you get the
>
properties does it copy all the properties of the current person in to
>
your variable?
Yes.
>
>
What if you need to update that field in the address book? Can you do:
>
set last name of theProp to "MyName"
All that does is change the value of that record property in the variable.
It doesn't change anything in the real person. On the other hand, if you
were going to make a NEW person, it would be a much faster way:
set newPerson to make new person with properties theProp
You still have to make the _elements_ (emails, IM fields, phones, addresses)
separately 'at' newPerson - they're not properties.
>
>
Or will that just update it in a local copy and not actually update the
>
address book?
Correct.
>
>
It is so slow though that it would be worthwhile to probably go through
>
and check if each property is different and only update the address
>
book if it is different.
Maybe: it also takes time to check (get) properties: that's an AppleEvent
too. But my own experience indicates that writing to disk is much slower
than just reading So getting 'properties' of each person and checking the
record, only setting what's changed, is definitely quicker. You also have to
check the properties of every element too, and only set those where
necessary, That's what I do with my "Sync Entourage-Address Book" script
(shareware, so run-only, sorry).
>
That would be a lot more code (right now I
>
just update all the fields from the fields in the Zaurus address book
>
if sync'ing from the Zaurus), but if it would speed it up it would be
>
well worth it.
A big thing you can do that will speed things up if there are a lot of
contacts is to do this. If the repeat loop is in the top-level of the script
(i.e. explicit or implicit run handler), then use 'my':
set thePeople to every person
repeat with i from 1 to (count thePeople)
set thePerson to item i of my thePeople
etc.
(Nigel Garvey discovered this. It's basically the same as 'a reference to'
but even faster.) If the repeat loop is in a handler, then 'my' and 'a
reference to' won't work unless 'thePeople' is a global', but this will -
thanks to Serge Belleudy-Espinoise (or correction):
script peopleScript
property myPeople: thePeople
end script
repeat with i from 1 to (count thePeople)
set thePerson to item i of peopleScript's
thePeople
etc.
(which won't compile in a top-level script). You see incredibly dramatic
differences in speed when the number gets high enough (say 1,000 or more: a
few seconds versus minutes for a simple list of strings), although not so
much for your 400. As you suspect, the slowness you're seeing is probably
not from iterating a repeat loop, but from re-writing every single property
and element of every single contact. in Address Book That's going to be
very, very slow.
--
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.