• 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: Christopher Nebel <email@hidden>
  • Date: Thu, 2 Dec 2004 10:05:21 -0800

On Nov 30, 2004, at 11:09 PM, halloolli wrote:

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.

Oh, duh. I'd noticed this myself and didn't think about it, but now that you mention it, it's obvious. AppleScript doesn't make any particular provisions for modifying a collection while you're looping over it, so you'll get odd results if you add and delete items. Getting the names beforehand is one way to deal with the problem (though I'd point out that it won't work very well if you have cards with the same name, as your company cards probably all do); here's the more canonical and efficient way:


	set all_people to every person
	repeat with p in all_people
		do_stuff_to_person(p)
	end

The trick is to get all the people first; you then have a list that's independent of who's where in AB's mind.

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. ;-) )

On a whim, I looked through the system dictionary (/usr/share/dict/words); there are no words listed that contain the string "nosync". I'd say you're pretty safe.


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".

"contains" is a polymorphic operator; it works on strings to do string containment, or on lists to do list containment. (As Paul Berkowitz is fond of pointing out, it actually does sub-list containment: for instance, {1, 2, 3, 4} contains {2, 3} is true, because the first list contains the sequence {2, 3}. This means that {{1, 2}, {3, 4}} contains {1, 2} is false; to get "true", you have to ask if {{1, 2}, {3, 4}} contains {{1, 2}}.)


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!

AppleScript is English-like, but it is not English. You might consider it a highly restricted subset of English: only specific syntax will work. Trying to "talk" to it as you would talk to a normal human will only cause trouble.



--Chris Nebel AppleScript Engineering _______________________________________________ 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
  • Prev by Date: Re: why is applescript so slow???
  • Next by Date: Re: display message while script is running
  • Previous by thread: Next Philadelphia Area AppleScript Users Group Meeting
  • Next by thread: Re: cost of repeats (was Re: why is applescript so slow???)
  • Index(es):
    • Date
    • Thread