• 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: Is there a more efficient way to do this?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Is there a more efficient way to do this?


  • Subject: Re: Is there a more efficient way to do this?
  • From: has <email@hidden>
  • Date: Mon, 11 Dec 2006 01:33:04 +0000

Paul Berkowitz wrote:

To find "overlapping" group members of _any_ email
address, you naturally need a repeat loop. But there are two ways of making
it faster:

There are various ways to speed things up: general optimisations like minimising the number of application commands used; optimising performance for specific use cases (e.g. if there's many items in the whitelist group, but only a few in the pimps group); using well-known hacks to speed up access to AppleScript lists; etc.


One possible speedup might be to build a list of whitelisted email addresses up-front. Another might be to get lists of all of the pimp email addresses and object references from Address Book using just two 'get' commands, and then munge all this data locally.

It's hard to make really concrete suggestions though without knowing more about how this code will be used, and the relative amounts of data it will need to handle.


If some of the contacts have more than one email address, it's trickier but
can still be done.

The following script uses Ruby + rb-appscript (Ruby's list processing facilities are a hundred times better than AS's, which saves lots of very tedious coding and runs faster), and optimises for the all-round worst-case scenario (i.e. lots of whitelist entries, lots of pimp entries, and any number of emails per entry):


#!/usr/bin/env ruby

require "appscript"
include Appscript

AB = app("Address Book")

# build a flat list of all whitelisted email addresses
whitelist = AB.groups["Whitelist"].people.emails.value.get.flatten
# p whitelist

# get a list of references and emails for the people to check
people = AB.groups["Pimps"].people
refs_and_emails = people.get.zip(people.emails.value.get)
# p refs_and_emails

# reject items that don't contain any whitelisted emails, then extract a list of references
refs = refs_and_emails.reject { |ref, emails| whitelist & emails == [] }.collect { |ref, emails| ref }


p refs
# [app("/Applications/Address Book.app").people.ID ("C25F63B1-12D0-11D7-8F34-000393DB78B6:ABPerson"), ...]



(Ruby's Array methods are described at <http://www.ruby-doc.org/core/ classes/Array.html> if you want to know more about what 'flatten', 'zip', 'reject', '&' and 'collect' do.)


has
--
http://freespace.virgin.net/hamish.sanderson/
http://appscript.sourceforge.net
http://rb-appscript.rubyforge.org


_______________________________________________ Do not post admin requests to the list. They will be ignored. AppleScript-Users mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: Archives: http://lists.apple.com/mailman//archives/applescript-users

This email sent to email@hidden
  • Prev by Date: Re: Find the intersection of two groups in Address Book.
  • Next by Date: Re: Importing/parsing CSV files
  • Previous by thread: Re: Is there a more efficient way to do this?
  • Next by thread: Re: Photoshop Image Size
  • Index(es):
    • Date
    • Thread