Last active
October 1, 2019 10:43
-
-
Save SamirTalwar/481da41d0f54004aeb138ddadb3a1853 to your computer and use it in GitHub Desktop.
JavaScript to add country codes to all phone numbers without them, for the Mac Script Editor.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
const countryCode = '+44' | |
const addCountryCodeToPhoneNumbers = person => { | |
for (const phone of person.phones()) { | |
if (phone.value().startsWith('0')) { | |
const newValue = phone.value().replace(/^0/, countryCode) | |
console.log(`${person.name()}: ${phone.value()} → ${newValue}`) | |
phone.value.set(newValue) | |
} | |
} | |
} | |
const contacts = Application("Contacts") | |
for (const person of contacts.people()) { | |
addCountryCodeToPhoneNumbers(person) | |
} | |
contacts.save() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment