An AppleScript to remove Address Book duplicates

Apr 14, '05 09:04:00AM

Contributed by: Safar

To get rid of duplicates in Address Book, I wrote the following AppleScript. Copy and paste it into Script Editor, and save it as a script. As Rob would say, "make sure you have a good backup." So from the file menu in Address Book, choose 'Export Database' first.

set liste to {}
set avirer to {}
tell application "Address Book"
  with timeout of 3200 seconds
    set code to ""
    repeat with this_person in every person --of group "bidule"
      set first_name to first name of this_person as string
      set middle_name to middle name of this_person as string
      set last_name to last name of this_person as string
      set full_name to first_name & middle_name & last_name
      if full_name is in liste then
        set lid to this_person's id
        set avirer to avirer & lid
      else
        set liste to liste & full_name
      end if
    end repeat
    repeat with une in avirer
      set bla to person id une
      set lenom to name of bla
      delete person id une
      save addressbook
    end repeat
  end timeout
end tell
[robg adds: I compiled the script, but haven't tested it. In 10.3.8, Address Book has a File: Back up Database option, which is probably what you should do before trying this script.]

Comments (7)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20050413112832556