Script to automatically produce enclosing folders?

I have had Devonthink for a number of years but I am now trying to use it in a serious way for data management. How difficult would it be to produce a script that takes a number of text files and replaces each of them with a folder of the same name as the text file that includes the text file? The intended use is to export several thousand bookends citations into Devonthink and then use the enclosing folders as the location for notes, quotes, outlines, pdfs, etc. If there was a way to produce these enclosing folders automatically it would be much easier. Thanks!

Yes, this is entirely possible.

tell application id "DNtp"
	activate -- This can be commented out when run inside DEVONthink, or not. :^)
	if selection ≠ {} then
		repeat with thisRecord in (selection as list)
			move record thisRecord to (create location ((location of thisRecord) & (name of thisRecord) as string))
		end repeat
	end if
end tell

Note that I don’t know the format of the names of your files, but there may have to be adjustments if the names contain : or /, as these will be interpreted as folder structures.

Also, you mention “several thousand” items. Test this on a small batch to see how it works first. It should be VERY quick to run.

tell application id "DNtp"
	set selectedItems to selection
	repeat with selectedItem in selectedItems
		set newDirectory to (create location (location of selectedItem & name of selectedItem))
		set theResult to move record selectedItem to newDirectory
	end repeat
end tell

Using tag groups might be more flexible especially if you are going to be annotating the documents.

Frederiko

I use my script at the following link to do generally what the OP requested (in a way that fits my own data needs) – I posted this in 2013 and it has proven to be the single script that I use more than any built-in feature of DEVONthink.

I have installed this script in ~/Library/Application Support/DEVONthink Pro 2/Scripts/Toolbar, with a custom icon for the script, and then installed it in the DEVONthink toolbar. A typical case for me: as I create drafts of client work products (combined with collateral artifacts, notes, etc., for that draft) I select the draft documents and collateral and use the script to quickly make a sub-group containing that draft. My script will suggest a name for the sub-group and optionally offer to append that name to the name of the parent.

Thank you so much BLUEFROG! The script worked exactly as anticipated. Now to figure out how to get the bookends references to have a useable name… :slight_smile:

My pleasure (and thanks from me to the other contributors as well) :smiley:

I have found the script posted by Bluefrog really helpful. However, the enclosing folders that were created always had the file extension added as well. The following script strips the extension and creates an enclosing folder named without an extension

tell application id "DNtp"
	activate -- This can be commented out when run inside DEVONthink, or not. :^)
	if selection ≠ {} then
		repeat with thisRecord in (selection as list)
			set oldName to name of thisRecord as string
			set AppleScript's text item delimiters to "."
			set oldNameString to text items of oldName
			set the newName to item 1 of oldNameString as string
			move record thisRecord to (create location ((location of thisRecord) & newName as string))
		end repeat
	end if
end tell