Skip to content

Instantly share code, notes, and snippets.

@leoherzog
Created February 20, 2019 19:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leoherzog/5ff887c9e9aacb5fad96a375a901ac32 to your computer and use it in GitHub Desktop.
Save leoherzog/5ff887c9e9aacb5fad96a375a901ac32 to your computer and use it in GitHub Desktop.
Add All Google Contacts with a Phone Number to a Label
var nameOfLabel = "Contacts With a Phone Number";
function run() {
var label = ContactsApp.getContactGroup(nameOfLabel);
if (!label) {
label = ContactsApp.createContactGroup(nameOfLabel);
}
var allContacts = ContactsApp.getContacts();
Logger.log("Searching " + allContacts.length + " contacts...");
for (var i in allContacts) {
var phones = allContacts[i].getPhones();
if (phones.length) {
Logger.log("Adding " + allContacts[i].getFullName() + "...");
label.addContact(allContacts[i]);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment