2

Is there a way to change the current labels in Contacts.app to custom ones using AppleScript based on a specific criteria?

Here is what I mean:

I need the script to go through my contacts to change the phone numbers default labels such as mobile, home, work, etc. to specific labels based on the first 3 digits of the phone number. If the label has been changed already or the criteria does not apply, then the script should skip that phone #.

Here is an example:

  • If the phone # starts with 079, then change the label to "zain"
  • If the phone # starts with 078, then change the label to "umniah"

Is this even possible?

2

Here is an example (quick scribble) of how to get and process the labels.

tell application "Contacts"
    set theNumber to "079"

    set (label of phones of people whose value starts with theNumber) to "test"
    save


end tell

Set theNumber to your own number.

AND I WOULD BACKUP THE ADDRESSBOOK BEFORE YOU START PLAYING WITH IT.

Update.

I have change the script to chaco if the phone number starts with rather than contains.


'label' = an items label. i.e 'mobile','iphone','home page'

Phones = the phone numbers of a person/contact's entry

people = plural for more than one person/contact.

value = the value of an item in a person/contact entry - in this case the phone number

In the set command the code between the brackets ( ) is run first.

Meaning the reference to phone number's label in whole of the address book that starts with theNumber is gathered in a list.

Then the surrounding code tells each reference to change to test.

  • Thank you for your response. Just to clarify: 1) What's the difference between the 9s and the 0s? Are they placeholders? 2) For "label of phones of people whose value contains theNumber", you mean the old label like "mobile"? Thanks again. – Melwan Sep 13 '13 at 19:10
  • The script is basically saying. Change the 'labels' of phone numbers of you contacts that contains theNumber to "test". This means when run if any persons (peoples) phone number meets the requirements then the matching numbers label will be change. Doing it this way saves iterating over each number, person and label. Especially if they is more than one number per contact. The "079999 0099999" text is just a number I know is not in my address book apart from the two i used for testing. I did not want all my real numbers change. – markhunte Sep 13 '13 at 20:42
  • I have updated the answer to have the script look for phone numbers that start with ... – markhunte Sep 13 '13 at 20:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .