• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: cost of repeats (was Re: why is applescript so slow???)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: cost of repeats (was Re: why is applescript so slow???)


  • Subject: Re: cost of repeats (was Re: why is applescript so slow???)
  • From: "halloolli" <email@hidden>
  • Date: Wed, 1 Dec 2004 18:09:54 +1100

sorry for the wrong post before: hit send instead of close. sorry! here my real reply:

From: "Andreas Amann" <email@hidden>

Well, the original example has some serious issues as well - I only looked at the main loop, as represented below:

tell application "Address Book"
set refPeopleList to a reference to name of every person
repeat with pName in refPeopleList
set p to (first person whose name is pName)
if (name of every group of p) does not contain "test" then
save addressbook
end if
end repeat
end tell

This takes 32 on my computer (without the run log showing) - (I don't have a group "test" defined).

The problem here is that you send a lot of queries to the AB - there really is no reason to do so:
[...]
So, the code above is identical to


tell application "Address Book"
repeat with p in people
if (name of every group of p) does not contain "test" then
save addressbook
end if
end repeat
end tell

at first, thanks for your detailed look at the script and thanks for youer suggestions.


however, i tried to loop through the people as well, but it did give me strange results: some entries were copied twice, others weren't copied at all. i reckon the resaon is that i create new persons in the loop which confuses the id-handling of AB. instead looping through the list of names works perfectly.

the strange result by looping through the people list made me try to save the adressbook more often, but that's probably not neccessary. i'll try it without continuous saves.

on dont_copy_this(pers)
   tell application "Address Book"
       set w to words of (note of pers as string)
       return w contains "nosync"
   end tell
end dont_copy_this

Why are you taking this into words first? No need to do so, you can simply use

on dont_copy_this(pers)
tell application "Address Book" to return (note of pers as string contains "nosync")
end dont_copy_this

true, thanks for this. (only difference is the second version would find "ohnosyncsucks" while the first one wouldn't. ;-) )


i'm not very expirienced in terms of knowing what a AS operator can do and what it can't do: so i didn't think that "contains" can test for mulitple entities at once: in your version "contains" tests on "n", then on "no", etc, while in my version it just compare list entries with the complete string "nosync".

on recreate_group(gName)
  ...

Can you possibly jump through more hoops to get the list of people in a group?

tell application "Address Book" to set delList to people of group gName

would be so much easier, better to read (and probably faster as well - I did not test this one...)

(I am not sure either whether you have to loop through each member of that list to delete them, I guess "delete delList" should work as well - I didn't try this for obvious reasons;-)

i'll go back to you on this one, but i think i have to loop through all members...


the strange thing with AS is: it appears to be intuitive like spoken language but in fact many things easiliy phrase as a spoken expression won't work... well, it's a challenge!

olli


_______________________________________________ Do not post admin requests to the list. They will be ignored. Applescript-users mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
References: 
 >Re: cost of repeats (was Re: why is applescript so slow???) (From: Andreas Amann <email@hidden>)

  • Prev by Date: Re: cost of repeats (was Re: why is applescript so slow???)
  • Previous by thread: Re: cost of repeats (was Re: why is applescript so slow???)
  • Next by thread: [ANN] Script Timer 2.2 released by Apps & More Software Design
  • Index(es):
    • Date
    • Thread