Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Address Book: check for membership in group

31 views
Skip to first unread message

Sven

unread,
Aug 11, 2012, 4:37:40 PM8/11/12
to
Hello

How can I check whether a specific contact is member of a (or any) group? The following bit of code doesn't work:

set aGroup to make new group with properties {name:"aGroup"}

if (aGroup does not contain apers) then
add apers to group "abc"
end if

Thanks

Patrick Stadelmann

unread,
Aug 13, 2012, 3:32:24 AM8/13/12
to
In article <3412306a-3aa1-48eb...@googlegroups.com>,
What do you mean "doesn't work" ? Your test will always be true: since
you juste created aGroup, it is obviously empty...

Patrick
--
Patrick Stadelmann <Patrick.S...@unine.ch>
Message has been deleted

Patrick Stadelmann

unread,
Aug 13, 2012, 9:57:45 AM8/13/12
to
In article <michelle-6A8ED2...@news.eternal-september.org>,
Michelle Steiner <mich...@michelle.org> wrote:

> It doesn't work like this:
>
> tell application "Address Book"
> set agroup to group "Family"
> set apers to person "test person"
> agroup contains apers
> end tell

"group" can contain objects other than persons, so agroup must be :

set agroup to every person in group "Family"

Also, for some reason, apers must be a list :

set apers to person "test person" as list

With these two modifications, it should work.
Message has been deleted

Sven

unread,
Aug 13, 2012, 6:58:21 PM8/13/12
to
Hello everybody

Thanks for your time and your support so far! Much appreciated!

Sadly, I'm not there yet.

All I want to do is loop through all the people in the address book and check whether each is in a specific group or not. I use the following code:


make new group with properties {name:"Test"}
set aGroup to make new group with properties {name:"aGroup"}
...
repeat with apers in every person
...
if (aGroup does not contain apers) then
add apers to group "Test"
end if
...
end repeat


Sadly, that results in:

error "«class azf5» id \"B6A79B60-EAE5-4412-9430-DFB4F36F58CB:ABGroup\" of application \"Address Book\" kann nicht in Typ list, record or text umgewandelt werden." number -1700 from «class azf5» id "B6A79B60-EAE5-4412-9430-DFB4F36F58CB:ABGroup" to list, record or text


So, as I interpret the error, I have a conflict of type for some reason...??

Patrick Stadelmann

unread,
Aug 14, 2012, 7:12:35 AM8/14/12
to
In article <21280821-d379-4994...@googlegroups.com>,
Sven <sven.b...@gmail.com> wrote:

> make new group with properties {name:"Test"}
> set aGroup to make new group with properties {name:"aGroup"}
> ...
> repeat with apers in every person
> ...
> if (aGroup does not contain apers) then
> add apers to group "Test"
> end if
> ...
> end repeat

As pointed before, since you just created aGroup, your test will always
be true and so you could as well just add every person to group "Test".

If you need the test, you need something like this :

if ((every person in aGroup) does not contain {contents of apers}) then

Sven

unread,
Aug 14, 2012, 11:58:06 AM8/14/12
to
Am Dienstag, 14. August 2012 13:12:35 UTC+2 schrieb Patrick Stadelmann:
> In article <21280821-d379-4994...@googlegroups.com>,
>
> As pointed before, since you just created aGroup, your test will always
>
> be true and so you could as well just add every person to group "Test".
>
> If you need the test, you need something like this :
>
> if ((every person in aGroup) does not contain {contents of apers}) then
>
> Patrick

> As pointed before, since you just created aGroup, your test will always
> be true and so you could as well just add every person to group "Test".
>
> If you need the test, you need something like this :
>
> if ((every person in aGroup) does not contain {contents of apers}) then


Of course will my test always be true(!) My code is a mere *snippet* for demonstration purposes. The whole program is much longer and it doesn't really make sense to paste the whole of it.

So, my problem still stands. The following suggestions doesn't do the job:

> if ((every person in aGroup) does not contain {contents of apers}) then

It results in:

error "«class azf5» id \"8F90DC76-6053-4CC5-982B-A00065B40741:ABGroup\" of application \"Address Book\" kann nicht in Typ list, record or text umgewandelt werden." number -1700 from «class azf5» id "8F90DC76-6053-4CC5-982B-A00065B40741:ABGroup" to list, record or text


All I want to do is loop through all the people in the address book and check whether each person is in a specific group or not, based on the following lines of code:

make new group with properties {name:"Test"}
set aGroup to make new group with properties {name:"aGroup"}
...
repeat with apers in every person
...
if (aGroup does not contain apers) then <- I need the correct way to test membership
Message has been deleted

Patrick Stadelmann

unread,
Aug 14, 2012, 12:46:44 PM8/14/12
to
In article <73e257e6-344b-49d8...@googlegroups.com>,
Sven <sven.b...@gmail.com> wrote:

> Of course will my test always be true(!) My code is a mere *snippet* for
> demonstration purposes. The whole program is much longer and it doesn't
> really make sense to paste the whole of it.

As a rule, you should always post a simple test case that can be
directly run, as opposed to snippets. It makes it much easier for those
who try to help you.

> So, my problem still stands. The following suggestions doesn't do the job:

This works for me, it will create "aGroup" with all contacts who are not
part of "Test".

tell application "Address Book"
set aGroup to make new group with properties {name:"aGroup"}
set bGroup to group "Test"
repeat with apers in every person
if ((every person in bGroup) does not contain �
{contents of apers}) then
add apers to aGroup
end if
end repeat
save
end tell

Sven

unread,
Aug 14, 2012, 4:54:00 PM8/14/12
to
Thanks a lot everyone, the following expression finally did it for me:

if ((every person in aGroup) does not contain {contents of apers})
then
...
end if

But just out of curiosity and for the sake of understanding AppleScript better: why is it that it requires curly braces {} for this expression to work? And what 'type' of variable is apers, that it requires to use 'contents of ...'?

Patrick Stadelmann

unread,
Aug 14, 2012, 6:23:20 PM8/14/12
to
In article <fa557c68-057d-456f...@googlegroups.com>,
Sven <sven.b...@gmail.com> wrote:

> But just out of curiosity and for the sake of understanding AppleScript
> better: why is it that it requires curly braces {} for this expression to
> work?

It shouldn't be needed AFAIK. It looks like a bug.

And what 'type' of variable is apers, that it requires to use 'contents
> of ...'?

If you run :

tell application "Address Book"
set p to people 1 thru 2
repeat with apers in p
end repeat
class of apers
end tell

you should get "person". Actually, it's not "person", it's a reference
to an item in a list, as illustrated by :

tell application "Address Book"
set p to people 1 thru 2
repeat with apers in p
end repeat
apers
end tell

Here you should get "item 2 of {person ID ... , person ID ... }"

When you retrieve the class in the first example, AS resolves the
reference, but it does not do that when passing "apers" back to the
application, which seems to confuse Address Book when this happens with
a "contain" statement. It works with the "add" statement, however.

The use of "contents of" forces AS to resolve the reference, so that
what gets sent to Address Book is a class "person" and not a reference
to an item in a list.
0 new messages