Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Recover corrupted Address Book data with group info Apps
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.
  • Currently 3.80 / 5
  You rated: 5 / 5 (5 votes cast)

Recover corrupted Address Book data with group info | 4 comments | Create New Account
Click here to return to the 'Recover corrupted Address Book data with group info' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Recover corrupted Address Book data with group info
Authored by: stormy on Mar 21, '06 06:11:54AM

I have a related problem that maybe could be solved in a similar way.

Due to some syncing strangeness (with Missing Sync 5 and my Treo 600), the phone numbers in the Treo appear in random order. i.e: contacts with several numbers will have "fax" listed on top, or "other" listed on top, etc.

However, the Address Book lists the fields in the right order, just like they were originally in the Palm.

I've also found out that when Quicksilver accesses phone numbers, they are in the same "random" order. That means the "random" order is somewhere inside the Address Book database.

So I think if I can find some way to fix the Address Book database and sort the phone fields in the same order for all the contacts, the Palm problem will be solved too.

Any hints?

[ Reply to This | # ]
Recover corrupted Address Book data with group info
Authored by: rjbMacOSXHints on Jan 16, '07 12:08:58AM
The first two steps of this worked great for me. I sucked the CSV file into neo office spreadsheet. Cleaned up the data and then wrote it out again as a CSV file. Note that you should use the comma seperation and use the " quote to quote the text (Its an option when saving the file as a CSV from Neo Office. And then you can import it right into Address Book using the File->Import->Text File option.

But step three did not work for me. The 2nd Applescript will not run on my Tiger 10.4 environment. Applescript does not know about the keyword findAndReplace that is used in the 2nd applescript. Do you need to load any other libraries or something? Thanks, Rob

[ Reply to This | # ]

Recover corrupted Address Book data with group info
Authored by: watts on Jan 16, '07 07:05:26PM

Your friend should probably devote some attention to backups, too.

[ Reply to This | # ]
Recover corrupted Address Book data with group info
Authored by: strahlenroboter on Oct 22, '07 01:00:43PM
Well, there are two things that I wanna comment here:

1. Place the forgotten function findAndReplace to the 2nd script from above
2. There's another single-step-way of rebuilding the groups out of categories which are being lost in the exports of of OS X 10.4.10 (at least there)

1. If you use the 2nd script above with the filename abgroups1_scpt.txt you should add the following lines in order to use the function findAndReplace. (I just found that somewhere else on the net. It was stolen anyway before I found it. So, i'm sorry not to be sure about the author):

on findAndReplace(tofind, toreplace, TheString)
	set ditd to text item delimiters
	set text item delimiters to tofind
	set textItems to text items of TheString
	set text item delimiters to toreplace
	if (class of TheString is string) then
		set res to textItems as string
	else -- if (class of TheString is Unicode text) then
		set res to textItems as Unicode text
	end if
	set text item delimiters to ditd
	return res
end findAndReplace

2. Single-step-way of rebuilding the groups out of categories used in vcards
I had the problem that my 4.0.5 (under OS X 10.4.10) could export all the data of my address entries well, but could not re-establish oder rebuild the group information which was correctly put under the key (identifier) 'CATEGORIES:' which is usually used in vcards. That's kind of bad. And Apple seems to be quite silent on the subject. I mean I was really looking around for a made sollution (that worked) on the web (because I don't like to build up an AppleScript at all). But I did not found anything, so I had to do something on my own anyway.

Actually there's another use for the script. I can use it for the exports my online addressbook which is driven by 'PHP iAddressbook 0.98' (see A really good online solution where you don't need to be uncertain about the service you get from .Mac

So, just two more words about the script. After an export, you have usually a vcf-File with all the vcards inside. Open (and import) it with Addressbook, just as usual. You'll see the categories in the 'note' field. Now it's the turn of my script written in AppleScript: script-filename: cat2group-scpt.txt. It goes thru all the entries of the addressbook, grabs the assignment information (you would say, the groups or categories) out of the 'note' field, creates the groups and puts the data-entry into it. It should leave the real comments or notes just as is while the textual information about the categories will be deleted in the data-entry.

Try it out with an almost empty addressbook (less than 100 entries) to figure out if it works and how long it needs to fulfill. Backup your data before. With more than 800 entries in over 30 groups, it will take about half an hour to finish (on a Mac Book Pro 2.33 Ghz).

BTW, be sure that you export the 'note' field for not losing your comments (see -> Settings). For the script, it's not important.

Use a zipped version, if you don't wanna copy/paste the script in the script editor and lose probably some characters: directory listing of the script

[ Reply to This | # ]