I have a script with a repeat loop, that scans all the people in my address book :
tell application "Address Book"
set foundset to people
repeat with theperson in foundset
--script here...
end repeat
end tell
I don’t need to run the script for people belonging to a given group.
Is there a way I can refine foundset to only the people who do not belong to this group ? (this would make the script run faster, because I would avoid the loop for the many people excluded)
I tried (for example “set foundset to people not contained in group A”) and I searched the forum, but I did not find a way.
tell application "Address Book" to get every person whose group is not NAMEOFGROUP
Than maybe you could use this:
tell application "Address Book"
set allGroups to every group whose name is not NAMEOFGROUP
set allPersons to {}
repeat with i in allGroups
set end of allPersons to every person of i
end repeat
end tell
Hope it works,
ief2
PS: I don’t actually use iCal, so I couldn’t test it
Your script works, but to make it correspond to my needs, I still would have to :
remove duplicates, because some people may belong to more than one group
add people who belong to no group at all
I think that I could manage to do that, but that the time needed to perform these operations is roughly the same as the time taken by treating in the loop the people of the group A.
tell application "Address Book"
-- Get every person
set allPeople to every person
-- add to list if not in wrong group and if not allready in
set allRightPeople to {}
repeat with i in allPeople
if group NAMEOFGROUP does not contain i then if allRightPeople does not contain i then set end of allRightPeople to i
end repeat
end tell
Your script should be working, but it necessitates to go through a loop examining all the people in my address book.
This is what I was looking to avoid, if it is possible, which I don’t know…
In my understanding, a statement using “whose” (or a similar expression) should be much faster than a script containing a loop. I can make such a statement to get all the people belonging to a given group, but did not find how to get the people NOT belonging to a given group.
Following your post, I tried the smart groups in address book ; it seems that there is a known bug, because I get a freeze of address book when I create the groups I need (system 10.5.8).