The renaming problem is is because of the layering, when groups contain nested groups. The group object has a layer number, which is the "floor" for the member objects, each member object will have a layer higher than its parent group.
When you create a new group which contains other groups, the newly created group "owner" will have a layer "floor" lower than the containing groups. Therefore given your code, the "last" group will be one of the member groups, not the newly created one. If the new group is going to contain every group on the card, then all the member groups will have a higher layer than the parent group, so your newly created all-encompassing parent group will be group number 1.
Contrast the following :
Code: Select all
repeat with i = 1 to the number of buttons of this card
set the selected of button i to true
end repeat
group
set the name of last group to "grpButtons"
Code: Select all
repeat with i = 1 to the number of groups of this card
set the selected of group i to true
end repeat
group
set the name of group 1 to "grpOvergroup"