Applescript to remove all contacts without a phone number

Discussion in 'Mac Programming' started by josephibb, Jan 24, 2011.

  1. josephibb macrumors newbie

    Joined:
    Feb 5, 2009
    #1
    Hi guys

    I used a Facebook to iPhone contact downloader and unfortunately it created about 200 new contacts for whom I do not have a phone number.

    Unfortunately iPhone sync does not have the option to only sync contacts with phone numbers :rolleyes: Why not? Anyway:

    I'm trying to create an Applescript to delete all contacts who do not have a phone number on their card. Does anyone know if this is achievable?

    Thanks. :)
     
  2. g-7, Jan 24, 2011
    Last edited: Jan 24, 2011

    g-7 macrumors 6502

    g-7

    Joined:
    Feb 14, 2006
    Location:
    Poland
    #2
    Select the contacts in Address Book you want to process and run this script.

    Code:
    tell application "Address Book"
    	
    	set lista to selection
    	repeat with osoba in lista
    		
    		if (number of phones of osoba = 0) then
    			delete osoba
    		end if
    		
    	end repeat
    	save
    	
    end tell
    It gets the list of all selected contacts and repeatedly tells Address Book to check the number of phone numbers for each person from the list, and if that number it is equal to zero, it deletes that contact. Then it saves changes.

    However, as iTunes allows you to sync a group selected from the Address Book, you might use this script instead:

    Code:
    tell application "Address Book"
    	
    	set grupa to make new group with properties {name:"With Phone Number"}
    	
    	set lista to selection
    	repeat with osoba in lista
    		
    		if (number of phones of osoba > 0) then
    			add osoba to grupa
    		end if
    		
    	end repeat
    	save
    	
    end tell
    It creates a new group in Address Book (called "With Phone Number") and copies there all the contacts from the selected ones that have at least one phone number.
     

Share This Page