(*
see: http://forum.devontechnologies.com/posting.php?mode=reply&f=4&t=16841
makes a child group of the currently selected group
(a group must be selected, else the script fails)
20130704 / 20141114 modified to create a new group with the proposed name
as a subgroup of the current parent
set to the first item in a selection (name can be overwritten),
then create a group with that name (or other specfied in the dialog),
then move the selection to that new group
*)
property nameSep : ": "
tell application id "DNtp"
set theSelection to (the first item of (the selection as list))
set theMoveSet to the selection
set currentGroup to current group
if the kind of theSelection is "group" then
set {nameOption, groupName} to {button returned, text returned} of (display dialog "Make group: enter group name" default answer "<name>" buttons {"Append to parent name", "Do not append to parent name", "Cancel"} default button 2 with title "Enter group name")
if nameOption is "Append to parent name" then
set groupName to (the name of currentGroup) & nameSep & groupName
end if
create record with {type:group, name:groupName} in currentGroup
else
set groupName to the name of (the first item of (the selection as list))
set {nameOption, groupName} to {button returned, text returned} of (display dialog "Move seleciton into New Group: enter group name" default answer groupName buttons {"Append to parent name", "Do not append to parent name", "Cancel"} default button 2 with title "Enter group name")
if nameOption is "Append to parent name" then
set groupName to (the name of currentGroup) & nameSep & groupName
end if
set theNewGroup to create record with {type:group, name:groupName} in currentGroup
repeat with thisItem in theMoveSet
set theResult to move record thisItem to theNewGroup
end repeat
end if
end tell