How to export a group as folders and convert individual .RTF and RTFD to files to .docx

DT 4.1.1 Sequoia

Hello, in order to collaborate on a project with people who know nothing about DT, I want to batch convert a DT group containing sub groups to a series of folders, convert individual .RTF and .RTFD files to.docx files, export PDF as PDF, .numbers and .pages as .numbers and .pages.

To process files individually would be a huge task, which I will have to repeat for other groups.

thank you very much

1 Like

Well, there is ‘Files/Export/Folders and Files’ (or whatever it’s called in the English UI). Certainly described in the user manual, I think.

Converting RTF and RTFD – Pages might be able to do that. And Pages is scriptable. Someone already did even write it for you, and a basic internet search turned it up as the first answer:

thank you. That was not my question.

You asked two things:

  • How to export groups as folders
  • How to automate conversion of RTF/RTFD to docx.

Which of those did I not answer? Or should I have mentioned that there’s an export command in DT’s scripting dictionary permitting the automation of the export?

The tools are all there; all you have to do is to cobble together a script using them.

3 Likes

OK, I will look. thank you

This is a one-off script. And as there’s no scriptable option to convert RTF(D) to .docx, a little bit of shell is used.
Select the group and run this script.

set tempdir to (path to temporary items)

tell application id "DNtp"
	if (selected records) is {} then return
	try
		set selGroup to (first selected record whose (record type is group))
		set allRTFs to search "kind:rtf" in (current group)
		if allRTFs is not {} then
			repeat with theRTF in allRTFs
				set {name without extension:recName, path:recPath} to theRTF
				set outputPath to (tempdir & recName & ".docx" as string) as string
				do shell script "textutil -convert docx " & (quoted form of recPath) & " -output " & (quoted form of (POSIX path of outputPath))
				set convertedDoc to import path outputPath to (location group of theRTF)
				if exists convertedDoc then
					tell application "System Events" to delete file outputPath
					-- move record theRTF to (trash group of (database of theRTF))
				end if
			end repeat
		end if
		export record selGroup to "~/Downloads" without DEVONtech_Storage
	on error
		display alert "Select a group before running this script." as critical
	end try
end tell

Note there is a commented out line moving the original RTF(D) to the database’s Trash. This is to not affect your original but can be uncommented, if needed. And yes, the original group could have been duplicated first but (1) I have no clue how large or small the group and (2) there’s no harm in including the originals.

1 Like

…in DEVONthink’s dictionary, or what do you mean? It seems to be possible via scripting Pages.

Howard Oakley mentioned textutil in a recent blog post, so I was also thinking about that option. However, he notes:

If the original file contains embedded images or other non-textual content, though, those aren’t included in the output.

I never used it before, so I did a quick test. Sure enough, converting an .rtfd with an image to .docx leaves out the image.

Opening the RTFD in Pages and exporting from there does include the image. So depending on the situation, scripting Pages might yield better results.


@rufus123 I’m curious, by the way: If .pages files are fine with your collaborators, why convert to .docx instead of .pages?

1 Like

I am very grateful for your time and effort.

I tried running the script both with the script editor and a Keyboard Maestro AppleScript action which should work.

I did not understand if the group should be chose in the sidebar or the file/folder list, so I tried both.

Out of 30 tries, the script worked once and results were spectacular. Exactly what I was looking for.

In the script editor, no error message apart from “must select a group” (although group selected). In Keyboard Maestro, I found the following in the engine log (name of the macro is GROUP .RTFD to .DOCX $wip - $wip means work in progress) :

text-script: line 1: `set tempdir to (path to temporary items)'
2025-12-12 19:55:35 Execute a Shell Script failed with script error: text-script: line 1: syntax error near unexpected token `('
text-script: line 1: `set tempdir to (path to temporary items)'. Macro “Convert GROUP .RTFD  to .DOCX $wip” cancelled (while executing Execute Shell Script).
2025-12-12 19:56:36 Execute macro “Convert GROUP .RTFD  to .DOCX $wip” from trigger Macro Set Palette
2025-12-12 19:56:36 Action 100318985 failed: Execute a Shell Script failed with script error: text-script: line 1: syntax error near unexpected token `('
text-script: line 1: `set tempdir to (path to temporary items)'
2025-12-12 19:56:36 Execute a Shell Script failed with script error: text-script: line 1: syntax error near unexpected token `('
text-script: line 1: `set tempdir to (path to temporary items)'. Macro “Convert GROUP .RTFD  to .DOCX $wip” cancelled (while executing Execute Shell Script).

thank you again VERY much

good point. There are RTF/D → Pages automator workflows that I can put in my services menu if there is no straightforward complete (including images) solution with docx. Your post just reminded me to also check for inline PDFs.

thank you very much

Correct.

@rufus123:
Selecting it in the item list, not the Navigate sidebar.

our post just reminded me to also check for inline PDFs.

Details matter.

1 Like