Exporting all documents from an intelligent Group

Hi,

I am using DEVONThink quite a while, but I would not call myself an expert, so hopefully my question has not been answered in another topic…

I created a folder containing different intelligent groups, collecting documents with a certain tag within those different groups.

I now would like to export the parent folder to my filesystem, having those intelligent groups each as a subfolder with the collected documents inside.

How is that done?

When I select all intelligent groups and use “export → files and folder…” (as I am using the German locale it’s “Exportieren → Dateien und Ordner…”) the file structure is created in my filesystem, but it contains no documents.

Is there another way? Am I doing anything wrong?

Thanks for your help,

Olli

Welcome @olli

A smart group doesn’t contain anything, so an export would only create an empty Finder folder.

You can manually select the results of a smart group and use File > Export > Files & Folders, exporting them to a specific Finder folder.

Development would have to assess changing the behavior of the export command with a smart group.

The other option is scripting. Here’s a simple script…

(* Exports selected smart groups to a Finder folder. Folder existence is validated; created if not extant. 
If run subsequent times, duplicates will be exported for document already exported. *)


tell application id "DNtp"
	if selection is {} then return
	
	repeat with theRecord in (selected records)
		if (class of theRecord is smart group) then -- Only process selected smart groups
			set recordName to (name of theRecord) -- Get the name of the smart group
			
			set exportDest to my dest(recordName) -- Check if the folder exists in the Finder, create it if not
			repeat with theChild in (children of theRecord) -- Export the items (children) in the smart group individually
				set fileExport to export record theChild to exportDest
			end repeat
		end if
	end repeat
end tell

on dest(recordName)
	tell application "Finder"
		try
			set exportDest to (alias ((path to downloads folder as string) & recordName as string)) -- Does the folder exist in the finder
		on error
			set exportDest to make new folder at (path to downloads folder) with properties {name:recordName} -- If not, create it
		end try
		return (POSIX path of (exportDest as alias))
	end tell
end dest

Dear Jim,

thanks a lot for your quick reply. However, as I have never used Apple Script before I have some really dumb questions:

  • where to put that script? I’ve guessed it’s placed within the “Contextual Menu” folder?
  • what’s the correct syntax for strings in Apple Script? I’ve tested around a bit, however I wasn’t successful…

The only thing I found in the net was something like casting it again with

POSIX path of (“/path/to/my/folder”)

But haven’t code for almost a decade, I simply failed :wink:

Maybe you can help me out - I know, those are really newbie questions, but I am really a beginner on that topic.

Thanks,

Olli

You’re welcome.

  1. Open /Applications/Utilities/Script Editor.app.
  2. Paste the desired code.
  3. Select Script > Compile to ensure it’s compiling properly.
  4. Select File > Save.
  5. In the Save dialog, press Command-Shift-G and paste ~/Library/Application Scripts/com.devon-technologies.think3/Menu. You can save into that directory or a subfolder of your choice.
  6. Give the script your desired name and save it. The script should now be available in the Scripts menu in DEVONthink.

Here is a different version using another approach.

property exportFolder : "~/Downloads/untitled folder 3/" -- You can drag and drop a Finder folder to insert a POSIX path here

tell application id "DNtp"
	if selection is {} then return
	
	repeat with theRecord in (selected records)
		if (class of theRecord is smart group) then -- Only process selected smart groups
			set recordName to (name of theRecord) -- Get the name of the smart group
			set exportDest to (exportFolder & recordName as string) -- Folder is created if it doesn't exist
			repeat with theChild in (children of theRecord) -- Export the items (children) in the smart group individually
				set fileExport to export record theChild to exportDest
			end repeat
		end if
	end repeat
end tell

PS:

POSIX path of (“/path/to/my/folder”)

/path/to/my/folder is already a POSIX path.

1 Like

Why the if selection … return at the start? If the selection is empty, the repeat should simply do nothing, shouldn’t it?

Yes, but it’s an example of error checking. It’s all too easy to write scripts with a stacked deck, e.g., having a selection made and that line is a good option for people to have in their toolbelt.

I see your point but beg to differ in this case.

Hi,

thanks a lot, that helped me out and it works like a charm!

/Olli

You’re welcome :slight_smile:

Do you understand what is going on in the script?

Yes, I just wasn’t aware of Applescripts’ Syntax…