# Move items maintaining same group structure

**URL:** <https://discourse.devontechnologies.com/t/move-items-maintaining-same-group-structure/87932>\
**Category:** DEVONthink\
**Created:** [October 30, 2026, 11:33am UTC](https://discourse.devontechnologies.com/t/move-items-maintaining-same-group-structure/87932 "2026-10-30T11:33:40Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Amparose](https://discourse.devontechnologies.com/user_avatar/discourse.devontechnologies.com/amparose/32/18224_2.png) [@Amparose](https://discourse.devontechnologies.com/u/Amparose)\
**Post date:** [October 30, 2026, 11:33am UTC](https://discourse.devontechnologies.com/t/move-items-maintaining-same-group-structure/87932/1 "2026-10-30T11:33:40Z")

</div>

I have an email archiving system that exports into an indexed folder where the mailbox structure becomes a folder structure, which ends up as a Groups structure. The problem I have is, after I move emails into the database, I don’t want them connected to the Finder folder structure and I can’t work out how automate relocating items retaining the same path. Say the indexed Finder folder has this:

- **Mailbox\_A/**
  - **Mailbox\_A\_A/**
    - Email 0001
    - Email 0002
    - etc

  - **Mailbox\_A\_B/**
    - etc

- **Mailbox\_B/**
  - etc

And in DT I have a database for emails like this:

- **Inbox (Indexed Finder folder)**
  - As above: Mailbox\_A/ etc

- **Email Archive**
  - Mailbox\_A
    - Mailbox\_A\_A
    - Mailbox\_A\_B

  - Mailbox\_B
  - Mailbox\_C

Is there a way to make a Smart Rule that moves everything from the indexed folders to Email Archive and either puts them into the correct existing sub-groups or makes group structures if they don’t exist?

“Just drag to the imported group” doesn’t work because:

1. Most mailboxes are incrementally exported over time.
2. Moving an indexed folder into DT works the first time but more emails to the indexed folder I end up with duplicate Groups hell.
3. Archiving emails is an ongoing, tedious task and I need it automated/easy/reliable

---

<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:** [October 30, 2026, 3:10pm UTC](https://discourse.devontechnologies.com/t/move-items-maintaining-same-group-structure/87932/2 "2026-10-30T15:10:22Z")

</div>

On the face of it, this should be easy to accomplish but…

- Is the _Email Archive_ a separate database?
- Are you adding more mailboxes and submailboxes to the indexed folder?

---

<div class="post-metadata">

**Author:** ![troejgaard](https://discourse.devontechnologies.com/letter_avatar_proxy/v4/letter/t/58956e/32.png) [@troejgaard](https://discourse.devontechnologies.com/u/troejgaard)\
**Post date:** [October 30, 2026, 5:40pm UTC](https://discourse.devontechnologies.com/t/move-items-maintaining-same-group-structure/87932/3 "2026-10-30T17:40:45Z")

</div>

What about DEVONthink’s native mail import?

To your question: I’m not sure if this can be done with standard smart rule actions, but it should be easy enough with a smart rule script.

The details of your setup matter, so it would be good to answer @BLUEFROG’s questions.

Here is an example, assuming the finder folder is indexed in the inbox of your “Email Archive” database (not the global inbox).

 ![Smart rule with script](https://devontech-discourse.s3.dualstack.us-east-1.amazonaws.com/uploads/original/3X/e/3/e3847a9c67a8c73927c222cedd9fabec0b194ac8.jpeg)

JavaScript:

```javascript
function performsmartrule(records) {
	const app = Application("DEVONthink");
	app.includeStandardAdditions = true;
	
	const indexedParentName = "Test - Email Export";
	// RegEx to avoid problems with group names containing "/"
	const pathSeparator = /(?<!\\)\//g;
	
	records.forEach(r => {
		const locParts = r.location().split(pathSeparator);
		// --> ["", "Inbox", "indexedParent", "Mailbox_A", ... , ""]
		const cutoff = locParts.findIndex(n => n === indexedParentName) +1;
		const subLocation = locParts.slice(cutoff).join("/");
		// --> "Mailbox_A/.../"
		const dest = app.createLocation(subLocation, {in: r.database});
		app.move({record: r, to: dest});
	})
})()

```

---

<div class="post-metadata">

**Author:** ![Amparose](https://discourse.devontechnologies.com/user_avatar/discourse.devontechnologies.com/amparose/32/18224_2.png) [@Amparose](https://discourse.devontechnologies.com/u/Amparose)\
**Post date:** [November 17, 2026, 9:41am UTC](https://discourse.devontechnologies.com/t/move-items-maintaining-same-group-structure/87932/4 "2026-11-17T09:41:00Z")

</div>

Thanks for the replies.

> Is the _Email Archive_ a separate database?

They are both in the same database.

> Are you adding more mailboxes and submailboxes to the indexed folder?

Yes, the content and structure of the Email Inbox (poor name as it’s not at all a database’s inbox) will vary over time as new Mailboxes are added and removed so it must be treated as transitory.

> JavaScript:

This changes everything…

Although I read that Apple hasn’t touched JavaScript for Automation (JXA) since 2015. Is it safe to build workflows around it?

Anyway, here’s where I landed (17,129 emails happily archived into folders so far): [hugyournet/MailMate-DEVONthink-email-archive](https://github.com/hugyournet/MailMate-DEVONthink-email-archive)

---

<div class="post-metadata">

**Author:** ![chrillek](https://discourse.devontechnologies.com/user_avatar/discourse.devontechnologies.com/chrillek/32/29340_2.png) [@chrillek](https://discourse.devontechnologies.com/u/chrillek)\
**Post date:** [November 17, 2026, 10:19am UTC](https://discourse.devontechnologies.com/t/move-items-maintaining-same-group-structure/87932/5 "2026-11-17T10:19:59Z")

</div>

> [@Amparose](#):
>
> Although I read that Apple hasn’t touched JavaScript for Automation (JXA) since 2015. Is it safe to build workflows around it?

Nor have they touched AppleScript for decades. They just abandoned any serious automation infrastructure. But yes, JXA is still there, it mostly works, and sometimes they even iron out bugs (without letting anyone know).

I use JXA regularly with DT. If it is “safe to build workflows around it” – who knows. If the gods at Apple decide to drop it and/or AppleScript, that’s that.
