# Save RTF to named subgroup of parent group?

**URL:** https://discourse.devontechnologies.com/t/save-rtf-to-named-subgroup-of-parent-group/17322
**Category:** Automation
**Created:** [May 7, 2014, 2:47pm UTC](https://discourse.devontechnologies.com/t/save-rtf-to-named-subgroup-of-parent-group/17322 "2014-05-07T14:47:40Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![sand.glue](https://discourse.devontechnologies.com/letter_avatar_proxy/v4/letter/s/41988e/32.png) [@sand.glue](https://discourse.devontechnologies.com/u/sand.glue)
#### Post date: [May 7, 2014, 2:47pm UTC](https://discourse.devontechnologies.com/t/save-rtf-to-named-subgroup-of-parent-group/17322/1 "2014-05-07T14:47:40Z")

</div>

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?

```auto

        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)

```

---

<div class="post-metadata">

### Author: ![korm](https://discourse.devontechnologies.com/letter_avatar_proxy/v4/letter/k/e0b2c6/32.png) [@korm](https://discourse.devontechnologies.com/u/korm)
#### Post date: [May 7, 2014, 3:35pm UTC](https://discourse.devontechnologies.com/t/save-rtf-to-named-subgroup-of-parent-group/17322/2 "2014-05-07T15:35:27Z")

</div>

Perhaps this will help with the technique to create a group

> [@New Group creation inside a Group](https://discourse.devontechnologies.com/t/new-group-creation-inside-a-group/15444/1):
>
> If I select a group in the Groups Pane (left one in the 3 panes view) and create a new group, the group is created inside the selected one and that’s fine (much better than the Finder’s behaviour). On the contrary, if the selected group is a leaf (lowest hierarchical level) the new group is created at the same level as the selected one and not inside it. I think it would be better (more consistent and more efficient) having new groups always created inside the selected one.

---

<div class="post-metadata">

### Author: ![sand.glue](https://discourse.devontechnologies.com/letter_avatar_proxy/v4/letter/s/41988e/32.png) [@sand.glue](https://discourse.devontechnologies.com/u/sand.glue)
#### Post date: [May 7, 2014, 3:55pm UTC](https://discourse.devontechnologies.com/t/save-rtf-to-named-subgroup-of-parent-group/17322/3 "2014-05-07T15:55:56Z")

</div>

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/](http://qandasys.info/how-to-pick-out-a-devonthink-record-or-group-within-the-current-group-using-applescript/).

---

<div class="post-metadata">

### Author: ![BLUEFROG](https://discourse.devontechnologies.com/user_avatar/discourse.devontechnologies.com/bluefrog/32/135_2.png) [@BLUEFROG](https://discourse.devontechnologies.com/u/BLUEFROG)
#### Post date: [May 7, 2014, 4:56pm UTC](https://discourse.devontechnologies.com/t/save-rtf-to-named-subgroup-of-parent-group/17322/4 "2014-05-07T16:56:47Z")

</div>

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

---

<div class="post-metadata">

### Author: ![sand.glue](https://discourse.devontechnologies.com/letter_avatar_proxy/v4/letter/s/41988e/32.png) [@sand.glue](https://discourse.devontechnologies.com/u/sand.glue)
#### Post date: [May 7, 2014, 5:20pm UTC](https://discourse.devontechnologies.com/t/save-rtf-to-named-subgroup-of-parent-group/17322/5 "2014-05-07T17:20:01Z")

</div>

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

```auto

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

```

---

<div class="post-metadata">

### Author: ![korm](https://discourse.devontechnologies.com/letter_avatar_proxy/v4/letter/k/e0b2c6/32.png) [@korm](https://discourse.devontechnologies.com/u/korm)
#### Post date: [May 7, 2014, 5:57pm UTC](https://discourse.devontechnologies.com/t/save-rtf-to-named-subgroup-of-parent-group/17322/6 "2014-05-07T17:57:45Z")

</div>

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

```auto

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.

---

<div class="post-metadata">

### Author: ![sand.glue](https://discourse.devontechnologies.com/letter_avatar_proxy/v4/letter/s/41988e/32.png) [@sand.glue](https://discourse.devontechnologies.com/u/sand.glue)
#### Post date: [May 7, 2014, 7:10pm UTC](https://discourse.devontechnologies.com/t/save-rtf-to-named-subgroup-of-parent-group/17322/7 "2014-05-07T19:10:09Z")

</div>

That works, thanks!

---

<div class="post-metadata">

### Author: ![system](https://devontech-discourse.s3.dualstack.us-east-1.amazonaws.com/uploads/original/2X/4/4e6ff70c96be2eb307a274d890bba8d71ba671b3.png) [@system](https://discourse.devontechnologies.com/u/system)
#### Post date: [January 21, 2022, 11:21am UTC](https://discourse.devontechnologies.com/t/save-rtf-to-named-subgroup-of-parent-group/17322/8 "2022-01-21T11:21:35Z")

</div>


