I apologize for jumping in, as I don't have an answer -- I found this because I have the same problem. I did want to clarify something, however: If I have to hand-delete a mass of groups (not as many as yours, but 100+), I am guessing that I should change the default address book to wherever I am deleting. Currently I have the iCloud version as a default, but I can't find where to even manually delete groups there..
I hope you get your answer -- I've subscribed to this tread just in case.
I have exactly the same problem.
I use iClud as default in all my devices and they all show the same contacts, including the groups. I dont have duplicate contacts, but hundreds of empy groups (groups with no name). It seems that an empty group replicates several times a day. I dont know how to stop this replication process and, additionally, I dont know how to remove hundreds of groups (apart from one at a time).
Any help will be greatly appreciated.
I'm sorry to say that in this case misery loves company. These reports tell me that sooner or later someone with programming chops or clout will get this bug and do something.
In my case it's not a priority -- I've given up on iCloud and Lion both and I kept my iMac on Snow Leopard. I'm back to synchronizing my Address Book with my iPhone via iTunes cable (it still works, still is the most reliable way to sync).
I'm going to try Mountain Lion on my MacBook Air and see if that provides any fixes, otherwise I'll wait and see if Apple fixes iCloud. I won't move my main machine to Lion, and I'll hold off going to Mountain until this bug is fixed.
I figured this out. In this case I didn't care about my Contacts, I had them elsewhere. My problem was my iCloud acount was "poisoned" with massive replication of 'Groups'. Even after I deleted all the Contacts I still had hundreds of Groups to get rid of. Manual deletion was too tedious.
The answer was a simple AppleScript (I'm on ML on the machine i ran this on, so it's "contacts" rather than Address Book:
tell application "Contacts"
repeat 50 times
set theGroup to group "MyGroupName"
Since I had the same Group Names replicated about 100 times each, I only had to run this about 10 times to clear them all out. When I got to smaller numbers I had to drop the repeat count. I changed the Group name as I went.
Took me about five minutes.
I'm sure an AppleScripter could turn this into a general script for removing all groups all at once. Or could get very clever, and only remove groups that had no contacts (so one could salvage the group/contact relationships).
I didn't need that. My problem has been fixed.
I think sync works a LOT better in ML than Lion btw. iCloud updated very quickly.
I apologize for asking what may be an obvious question, but I've probably use Scripts once in the past decade.
My 300+ Groups don't even have a name -- it's just a list of empty groups called "Group Name" -- Do I need to change your script to reflect something different in the quotation marks?
Thanks for your help.
I had a similar problem (Lion OS X). Hundreds of duplicates of 3 Groups. Was driving me nuts trying to work a way of deleting them.
For the record, my problem started when I created multiple tags in Cobook which syncs with Address book. These tags create Groups in Address Book.
The script sorted it in 15 mins once I'd worked out how to use it. Thanks jfaughnan!
I have the same with duplicate groups, I have a few thousand and it's taking ages to remove them.
I think the reason for my duplicates was becuase I have two email addresses registered with itunes and iCloud (my personall email and my .me address. This is what triggered it, however I now I have the nightmare of deleting them.
I have run scripts in setting up OpenGL programs on my Macs. I cannot get your script to execute, however, and have tens of thousands of "untitled group"s in my contacts in the cloud. Does each line in the script need to be entered separately into Terminal, all in one line, or something different yet? Please advise.
The script works. It turns out I had over 10,000 of these untitled groups, as a result of trying to get these groups out of several devices and re-syncing over and over. Don't do that. Do this...
1 - MUST have ALL devices set to sync the Contacts with icloud - iCloud Contacts turned on.
2 - don't run any apps or use the internet while doing this - it really slows down the response time of everything.
3 - run the script on your computer that has the contacts as many times as it takes until it tells you if is unable to find the groups you are trying to delete. You may have to adjust the number you are wanting to delete to a lower number when it gets close to the end. You know you are close because the script runs much faster towards the end.
4 - give it a lot more time to sync with all the devises - just walk away. I went to bed and the next day all the untitled groups were gone from all devices, my computer and my iCloud account.
This script did not run on 10.7.5, but worked fine in 10.8.3