I would like to list all contacts on the iOS device

#1

Is there a script that will list all contacts that are currently on the device? I’m still learning java and this app is great!

#2

I don’t have a full script that does this but you can use Contact.all to fetch the contacts. Here’s the documentation: https://docs.scriptable.app/contact/#all

1 Like
#3

I tried that. It won’t seem to work.

#4

It worked fine for me. I used the following.

let containers = await ContactsContainer.all();
let contacts = await Contact.all(containers);
contacts.forEach(function(contact){console.log(contact.givenName + " " + contact.familyName);})

As per the docs, it takes a set of contact containers as the parameter for all, and if I just get all the containers and pass that in, I get all of my contacts in all of my addressbooks back which I then wrote out to the console.

Please also note that Scriptable uses JavaScript, not Java. It is important to understand the difference.

5 Likes
#5

Thanks for the sample code.

I recently had an issue that after switching carrier I noticed that I can’t call some of my contacts. It ended up related to having a 0 between the country code and the area code.

In order to find all the problematic contacts, I used this script:

let containers = await ContactsContainer.all();
let contacts = await Contact.all(containers);
contacts.forEach(function(contact){
  let pn = contact.phoneNumbers.map(p => p.value).join(", ");
  let cleanPn = pn.replace(/[^0-9,]/g,"");
  if (cleanPn.match(/\b9720/)) {
    console.log(`${contact.givenName} ${contact.familyName}: ${cleanPn}`);
  }
});

I didn’t want to do the extra step of fixing the phone number automatically, but that’s doable as well.
If you want to reuse the code, you will need to replace 972 with your country code.

1 Like