groups

info


tags: applescript,address,book

Link to this snippet:


Download to Code Collector

language: AppleScript
licence: Other

Cleanup @ Entries - Address Book

options: send to code collectorview all seydoggy's snippets
(*
Cleanup @ Entries

By Adam Merrifield <http://seydoggy.com>

This script will cause irreversible changes
to contacts in your Address Book.

USE AT YOUR OWN RISK!!

This script looks for entries in the Address Book that do not have proper first or last names and instead use an email address as one or the other. I personaly have no use for a contact with no name but this might be the case with you. This will likely wipe out a big chunk of your contacts, so I repeat, USE AT YOUR OWN RISK!!

- r1 12-23-09 13:31
*)
tell application "Address Book"
	activate
	set thePeople to (every person whose first name contains "@" or last name contains "@" or middle name contains "@")
	repeat with i from 1 to count of thePeople
		set thePerson to (item i of thePeople)
		set firstName to (first name of (item i of thePeople) as string)
		set lastName to (last name of (item i of thePeople) as string)
		set middleName to (middle name of (item i of thePeople) as string)
		set theirEmails to (value of email of (item i of thePeople) as string)
		set urlList to {"com", "net", "ca", "org", "uk", "us", "fr", "it", "edu", ".com", ".net", ".ca", ".org", ".uk", ".us", ".fr", ".it", ".edu"}
		
		if first name of (item i of thePeople) is missing value or last name of (item i of thePeople) is missing value then
			delete thePerson
		else if firstName contains "@" and lastName contains "@" then
			delete thePerson
		else if urlList contains lastName then
			delete thePerson
		else
			display dialog "first name: " & firstName & return & "middle name: " & middleName & return & "last name: " & lastName & return & return & theirEmails buttons {"Cancel", "KEEP", "DELETE"} default button "DELETE" giving up after 30
			copy result as list to {the buttonReturned, the gaveUp}
			if gaveUp is true then error number -128
			if buttonReturned is "Canceled" then error number -128
			if buttonReturned is "DELETE" then delete thePerson
		end if
		save
	end repeat
end tell