Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

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 
save
end tell

Any help will be much appreciated.

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

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"
    repeat
        try
            set theGroup to group theGroupName
            delete theGroup
            set counter to counter + 1
        on error
            exit repeat
        end try
    end repeat
    save
    display dialog "Removed " & counter & " instances of the group" with icon caution buttons {"OK"} default button "OK"
end tell
share|improve this answer
    
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 '12 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 '13 at 13:46
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.