Q: Remove spaces in phone numbers in Contacts
Hi,
How do I remove/reformat phone numbers in the Contacts app in OS X El Capitan?
Phone numbers have spaces eg +61 111 222 333 and when using Copy + Paste get rejected by my VOIP application.
Thanks!
iMac, OS X El Capitan (10.11.2)
Posted on Sep 16, 2016 9:24 PM
I found a way to make a plugin that will strip non-numeric characters from the phone number.
Copy the following and paste it into a new Script Editor document.
using terms from application "Contacts"
on action property
return "phone"
end action property
on action title for selectedPerson with thisPhoneNumber
return "Copy Digits"
end action title
on should enable action for selectedPerson with thisPhoneNumber
return true
end should enable action
on perform action for selectedPerson with thisPhoneNumber
set phoneToCopy to (value of thisPhoneNumber) as string
set the clipboard to returnNumbers(phoneToCopy)
end perform action
end using terms from
on returnNumbers(phoneNumber)
set theDigits to {"+", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}
set onlyNumbers to ""
repeat with i from 1 to length of phoneNumber
set j to (character i of phoneNumber)
if j is in theDigits then set onlyNumbers to onlyNumbers & j
end repeat
return onlyNumbers
end returnNumbers
Save the script into your user Library/Application Scripts/com.apple.AddressBook folder.
To get to the user Library, hold down the Option key and select Library from the Go menu in Finder.
When you click on the phone number label in Contacts, Copy Digits will appear in the list.
If your VOIP software is scriptable, it might be possible to just have it dial from that menu.
I wrote it to allow + symbols in the string. Does your VOIP software understand the + or does it need to be stripped out?
Posted on Sep 17, 2016 5:57 PM