Well, I have this friend who knows a lot about music but little about computers. He continued to use his iBook until his hard drive was very, very corrupted, S.M.A.R.T had long given very definite warnings. So there he was, with a completely-corrupted Address Book database, with his 2,000 contacts in there, ordered into about 40 groups. Without that information, he would have had to start on the sidewalk again. Backup? .... Backup? None of that!
Well, here is what I did: To get rid of the corruption, I used Address Book Exporter to export the data into plain text format. Then I deleted all Address Book information (preferences and database) and re-imported them with the built-in import function. There were only about 1% of the addresses lost, and the size of the Address Book database file shrunk from 18MB to 2MB.
The problem with this approach is that the information about the groups gets lost. So I wrote this little AppleScript. It appends all group names the person is in to the notes of that person, enclosed in brackets. In doing this, I enclosed the group information into the person information. Note that it has two try....end try error handlers, which write occuring errors into a file called errors.txt on your Desktop (without checking whether this file existed before!). There you can see which contacts are corrupted, as they will not be readable with AppleScript. This script has to be executed before using Address Book Exporter.
After reimporting the text file with the adresses, I then ran this AppleScript. It recreates the groups and re-assigns the persons. Now (and with a new hard disk), my friend can concentrate on making music again.
Mac OS X Hints
http://hints.macworld.com/article.php?story=20060316072002266