Save RTF to named subgroup of parent group?

I’m trying to write a script that would create a new RTF in a subgroup (named in the script) of the current group. The problem is that the script creates a new group even if the group already exists. Does anyone know how to make the script check if the group exists, and place the RTF in the existing group? The only way I could find requires the path (in the database) to the group. Is there a way to get the path of the current group?


        set parentgroup to parent of content record of window 1
        if not (exists record at groupPath???) then
                set theNewGroup to (create record with {type:group, name:groupName} in item 1 of parentgroup)
        else
            set theNewGroup to get record at groupPath???
        end if
        set targetgroup to theNewGroup
        set myRecord to (create record with {type:rtf, name:theName, rich text:theText} in item 1 of targetgroup)

Perhaps this will help with the technique to create a group

Thanks, but that scripts does the same thing it seems. Is there a way to get the path of parent group?

There are also some ideas in this post, but I’m not sure how to implement them http://qandasys.info/how-to-pick-out-a-devonthink-record-or-group-within-the-current-group-using-applescript/.

The location of the record is the record path sans the filename.

Could you put that in context? This does not work:


set path_parentgroup to the location of (parent of content record of window 1)

This snippet will create a group (without duplication):

  • if the selected item is a document, then the new group is created as a child of that document’s parent

  • if the selected item is a group, then the new group is created as a child of that group


tell application id "DNtp"
	
	set theRecord to the first item of (the selection as list)
	set theLocation to the location of theRecord
	if the kind of theRecord is "Group" then
		set theLocation to theLocation & the name of theRecord & "/BLAH"
	else
		set theLocation to theLocation & "/BLAH"
	end if
	set theGroup to create location theLocation
	
end tell

If using “create location” then you don’t need to know if the group already exists, since that statement automatically ensures that if a group with that name at the location exists, then a new one is not created.

That works, thanks!