Forum Archive

Contacts in a group

Jaap

How could I list all contacts in an existing group ?
(pythonista contacts module)

I would like to write a script that provides me with all email addresses in a contacts-group to use in emailing the group in one action.

omz

I just realized that the documentation for this is missing, but Group objects have a get_members method that returns a list of all contained Person objects.

Jaap

;-) Thanks a lot

MartinPacker

@omz If it's missing in the Pythonista docs does it exist in Editorial? (Or is the module not present in Editorial?)

ccc

You can run this code to find out if the contacts module is present and if it contains a get_members() method.

import inspect, contacts
print('=' * 20)
groups = contacts.get_all_groups()
if groups:
    for member in inspect.getmembers(groups[0]):
        print(member[0])
else:
    print('You have no groups!')
omz

The whole contacts module is not yet available in Editorial.

ihf

I was wondering why when I do contacts.find('anyname') I always get 2 person objects returned for each result found by the Contacts.app.

ihf

Does this only happen to me (duplicate objects returned) or is this expected?

ihf

OK, further experimentation has demonstrated to me that I have duplicates of all contacts (I added one and it displayed properly). Can anyone tell me: 1. how does this happen? 2. does the Contacts.app only show one copy? 3. most importantly, is there a simple way to remove the duplicates?