Reputation: 3
This is my first post in stackoverflow. I've spent weeks trying to get an Applescript to remove people from established Groups (not Smart Groups) in Contacts (Mac Address Book). The script removes several people then issues an error. If I re-run the script after the error is issued, it will remove a few more people from the group and then issue the same error again. I can continue doing this until eventually everyone is removed from the group. I don't understand why the error is issued when re-running the script after the error is issued results in a few more people being removed before the error is issued again. - And again, I can continue re-running the script until eventually every person is removed from the group. This suggests the contact records are not corrupted.
I've tried moving the SAVE command around but that didn't help. The Group I'm removing contacts from is labeled "Family".
The error issued is... error "Contacts got an error: Can’t get group \"Family\"." number -1728 from group "Family"
tell application "Contacts"
set group_list to name of every group
repeat with anItem in group_list
set AppleScript's text item delimiters to ""
repeat 1 times
if first item of anItem is not "$" then exit repeat
set AppleScript's text item delimiters to "$"
set gruppe to text item 2 of anItem
if group gruppe exists then
--remove every person from group
repeat with person_to_remove in every person in group gruppe
set firstName to first name of every person in group gruppe
set group_count to count every person in group gruppe
remove person_to_remove from group gruppe
save
end repeat
end if
end repeat
end repeat
save
return "Done"
end tell
Upvotes: 0
Views: 1426
Reputation: 17640
I think you're trying to hard. There is no need to change applescripts text item delimiters you can still find out if the group has a $ a the beginning of the group name
creating a 1 time loop is just weird not sure why you chose to do it that way.
you know the group already exists because you are looping through them so no need for that either
so here it is
tell application "Contacts"
set group_list to name of every group
repeat with aGroup in group_list
if first item of aGroup is "$" then
set thePeople to every person in group aGroup
repeat with aPerson in thePeople
remove aPerson from group aGroup
end repeat
end if
end repeat
save
end tell
Upvotes: 2