Find and delete duplicate field info in Address Book

I imported all my Address Book data quite awhile ago, and ended up with the first name appearing twice, once in the correct field and once in the Prefix field. So my entry now reads “John John Doe” instead of “Mr. John Doe” or just “John Doe” (which would be fine – I don’t need the Prefix populated.

I’d like to create a script that finds records where the Prefix and First Name fields match, then deletes the Prefix content. If they don’t match, it leaves them alone.

Sounds easy, except I’m not a scripter. Anybody know of something like this that already exists, or could be modified?

Thanks!

Model: MacBook Pro 15" 2.4 GHz Core Duo
AppleScript: 2.2.1 I guess (current)
Browser: Safari 4.0.3 (5531.9)
Operating System: Mac OS X (10.5)

If you go to the Template pane of AB preferences, you could just turn the prefix off and they won’t show.

If that doesn’t satisfy, you could just set all titles to “”, that is assuming that you don’t have titles in some persons (entries).

tell application "Address Book"
	set P to every person -- returns a reference to every entry
	repeat with oneP in P
		set title of oneP to "" -- prefixes are called titles in AppleScript
	end repeat
end tell

If you do use titles in some entries, then you’ll have to go through the list of every person’s first name and title properties and if neither of them is missing value compare them. If they’re the same, set the title to “”. Do you want to go there? I hesitate to give you that script not knowing what other things it might screw up in your address book – I don’t know how you enter stuff.

A word of warning about doing things from an AppleScript – changes won’t show unless you deselect the person and re-select them.

Thanks for your help with this, Adam. My address book has over 2000 names. I’m really trying not to do this by hand if possible.

Your idea about just turning the Prefix field off isn’t bad…but I know I’d rather have my data be accurate. And I’d rather be able to use “Dr.” and so on if I need it. So, yeah, if there’s a way to compare the contents of the two fields and, if they match, then just set the Prefix to “”", that sounds perfect.

I can certainly make a backup of my data before I run it in case it screws something else up. But if it focuses only on the two fields in question, I think I should be okay.