Use JavaScript to Automate stuff on macOS

var contacts = Application("Contacts");
var people = contacts.selection();
console.log("Processing: " + people.length + " Contacts")people.forEach( person => {
let phones = person.phones();
phones.forEach( phone =>
let num = phone.value();
let n = num.replace("(","").replace(")","");
if( n[0] === " " ) n = n.substr(1)
if( n[0] === "0" ) n = n.substr(1)
if( n.startsWith("77") ||
n.startsWith("72") ||
n.startsWith("76") ||
n.startsWith("71")) {

phone.value = "+94" + n;
console.log(person.firstName() + " " + phone.value())
}
});
});
contacts.save();

--

--

Coder, Creator of things, Entrepreneur

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store