dm4n

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

Close

Q: Remove spaces in phone numbers in Contacts

  • All replies
  • Helpful answers

  • by Barney-15E,Helpful

    Barney-15E Barney-15E Sep 17, 2016 5:41 PM in response to dm4n
    Level 9 (50,401 points)
    Mac OS X
    Sep 17, 2016 5:41 PM in response to dm4n

    I can't find a way to alter the copying of the number format in Contacts. The numbers are formatted to match the country code generally recognized formatting. Even if you enter the numbers without formatting, the display will be formatted and anything you copy will too.

     

    Contacts has a Plugin architecture. Perhaps the VOIP software has a plugin for Contacts that allows you to dial from the label menu in Contacts. Or, perhaps there is a plugin out there that will copy the number without the formatting (though, I didn't find one when googling).

     

    You could contact the VOIP software developers and ask them to fix their app because it should be stripping all non-numeric data from the string. It has no idea where you would copy a number from (like a website), and it should be able to parse out the number.

  • by Barney-15E,Solvedanswer

    Barney-15E Barney-15E Sep 17, 2016 5:57 PM in response to Barney-15E
    Level 9 (50,401 points)
    Mac OS X
    Sep 17, 2016 5:57 PM in response to Barney-15E

    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?

  • by Luis Sequeira1,

    Luis Sequeira1 Luis Sequeira1 Sep 17, 2016 8:39 AM in response to Barney-15E
    Level 6 (12,436 points)
    Mac OS X
    Sep 17, 2016 8:39 AM in response to Barney-15E

    What about just clicking the Edit button in Contacts and manually removing the spaces?

  • by Barney-15E,

    Barney-15E Barney-15E Sep 17, 2016 9:20 AM in response to Luis Sequeira1
    Level 9 (50,401 points)
    Mac OS X
    Sep 17, 2016 9:20 AM in response to Luis Sequeira1

    Luis Sequeira1 wrote:

     

    What about just clicking the Edit button in Contacts and manually removing the spaces?

    Give it a try. Didn't work for me. It auto formats for display.

  • by dm4n,

    dm4n dm4n Sep 17, 2016 5:57 PM in response to Barney-15E
    Level 1 (4 points)
    Mac App Store
    Sep 17, 2016 5:57 PM in response to Barney-15E

    Perfect!

     

    It took me a while to recognise that the phone number 'label' eg mobile/home/work is a clickable field.

     

    Copy Digits shows up as an option and does the job.

     

    I use an online service to send SMS occasionally - and it was rejecting phone numbers formatted by OS X Contacts app.

     

    Re: the preceding '+' - my VOIP app (LinPhone) accepts it no problem.

     

    Thanks so much for your plugin. Kudos!