About this blog…

I am employed by Netnod as head of engineering, research and development and am among other things chair of the Security and Stability Advisory Committee at ICANN. You can find CV and photos of me at this page.

As I wear so many hats, I find it being necessary to somewhere express my personal view on things. This is the location where that happens. Postings on this blog, or at Facebook, Twitter etc, falls under this policy.

The views expressed on this post are mine and do not necessarily reflect the views of Netnod or any other of the organisations I have connections to.

Addressbook Sync problems in MacOSX

I have got ghost records in my addressbook. Records that have only an email address in them. The problem is that there are now and then thousands of those records. I have also, like many others, got problems with the updated format of images in the records in MacOSX 10.5.x. Many findings on the net suggest doing complete reset of the sync database on all computers (iPhone etc), but I do not want that. Why should I? Then rumors said the sync problem would go away in 10.5.3, but it did not. Or rather, the image syncing is better (but not resolved), but I get these bogus records.

To remove all of those records, I could either select those (one can find them in the Address Book by searching), do select-all, and then delete. The problem is that the “select-all” operation was never succeeding with the 16k bogus records. I had to kill Addressbook application after 4-5 hours with 100% CPU load. I could mark about 50 records at a time, and do manual delete, confirm etc, but each one of those took 20-30 seconds. Not a good solution either.

So I wrote an AppleScript. When running it, I could delete about 200 records every 25 minutes. Good enough. After running this, the 16k bogus records where gone. But, of course about 2k of them came back when syncing (again) with my iPhone that seems to have got some of them from my Mac. I am happy I wrote this script, as I now could run it again. Much faster when only having 2k bogus records. But still slow.

tell application "Address Book"
	set r to 0
	set nr to 0
	set pp to every person
	repeat with p in pp
		set ee to every email of p
		repeat with e in ee
			if (value of e) = "bogus-email@example.com" then
				set r to 1
			end if
		end repeat
		if r = 1 then
			delete p
			set nr to nr + 1
			if nr = 200 then
				save addressbook
				set nr to 0
			end if
		end if
		set r to 0
	end repeat
	save addressbook
end tell

AppleScript that remove records with certain email address

Comments are closed.