I would like to have a script to delete all my groups in my Contacts. Somehow I got a kind of replication bug resulting in over 500 groups.
Delete them one by one is not an option.

Tried this script, but it does not do the job, I have to enter to many group names and after a while the sript stops even when not all groups have been deleted.

tell application "Contacts" 
repeat 50 times 
set theGroup to group "MyGroupName" 
delete theGroup 
end repeat 
end tell

Any help will be much appreciated.

1 Answer 1


The reason that script doesn't delete all the bogus groups is that it only repeats 50 times, so it will only delete 50 in one go.

This script will delete every group with the name that you input (it asks you with a dialog box) until it can't find any more:

set counter to 0
display dialog "Name of group to delete?" default answer ""
set theGroupName to text returned of result
tell application "Contacts"
            set theGroup to group theGroupName
            delete theGroup
            set counter to counter + 1
        on error
            exit repeat
        end try
    end repeat
    display dialog "Removed " & counter & " instances of the group" with icon caution buttons {"OK"} default button "OK"
end tell
  • 1
    Daniel Thanks, works great. Even when I repeated my script multiple tmes, it did not do the job. Thanks for your solution. Most appreciated
    – James
    Oct 1, 2012 at 17:15
  • I had a bunch of group names as follows:"<Z name=/syncservicesagent/NoCategoryLabel comment='same label that is used for No Category item in category lists'>No Category</Z>" The simple script did not work but the above more lengthy one did the trick. Thank you for sharing.
    – user52945
    Jul 9, 2013 at 13:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .