Devonthink & Tinderbox Integration AppleScript (Batch notes creation error)

My task: Create new Notes in Tinderbox based on metadata in selected items in Devonthink (eg. aliases; URL; annotation). And put all the new note into according Note based on aliases in Devonthink. In this script below is “THTG”

My script:

-- Get the selected records in DEVONthink
tell application id "DNtp"
	set theSelection to the selection
	if theSelection is {} then
		display dialog "Please select a file in DEVONthink."
	end if
	-- Iterate through selected items
	repeat with theRecord in theSelection
		set recordAliases to aliases of theRecord
		set recordURL to URL of theRecord
		set recordAlias to get custom meta data for "group" from theRecord
		set recordRefURL to reference URL of theRecord
		set recordCreationDate to creation date of theRecord
		set recordReceiver to get custom meta data for "Receiver" from theRecord
		set recordText to get custom meta data for "tinderboxtext" from theRecord
		-- Check for alias "THTG"
		set parentName to "THTG"
		if parentName is in recordAlias then
			set parentNote to "THTG"
			set parentNote to "Uncategorized"
		end if
		-- Convert the creation date to text format
		set recordCreationDateText to short date string of recordCreationDate & " " & time string of recordCreationDate
		-- Create a new note in Tinderbox
		tell application "Tinderbox 9" -- Adjust according to your version of Tinderbox
			tell front document
				-- Check if the parent note exists, if not create it
				if not (exists note named parentNote) then
					make new note with properties {name:parentNote}
				end if
				-- Create the new note under the parent note
				tell note named parentNote
					set newNote to make new note
					set name of newNote to "[" & recordAliases & "]" & "-" & recordURL
					set text of newNote to recordText
					set value of attribute "URL" of newNote to recordRefURL
					set value of attribute "CreatedDate" of newNote to recordCreationDateText
					set value of attribute "VB_ID" of newNote to recordAlias
					set value of attribute "Receiver" of newNote to recordReceiver
				end tell
			end tell
		end tell
	end repeat
end tell

Problem: The script work as intended but when you selected 5 files at the same time in devonthink, it cause problem: some of the note will be missing data for no reason. (I have 2000+ files, so running it one by one is not an option).

Can anyone help me with my case ?

UPDATE: I think I know the cause of missing data. Its is due to the

Check for alias “TGTG”

when I selected files in Devonthink that not contains value “THTG” in recordAlias the note will got to Uncategorized parentNote.

And anything that come into Uncategorized have full metadata from Devonthink. I tried to add delay 1 second delay before set recordCreationDateText but its not solve the problem.

You could set

tell application "Tinderbox 9"


tell application id "Cere"

which is the bundleid for Tinderbox, which remains available no matter which version of Tinderbox you have installed.

I would not use scripting for this task. Do a search in DEVONthink. Select all the search results. Use the DEVONthink command Tools > Create Metadata overview. Display that as a sheet. Select all the rows of the sheet. Copy. Paste into Tinderbox. One note per row will be created. It takes longer to explain this than to do it.


The problem is not about bundleid for Tinderbox, its something have to do with checking every Devonthink files metadata before adding to Tinderbox note.

Base on your methods, I know its will work but it will contains more steps (Day 1
0-Search/Filter files
1-Select all the files
2-Create metadata overview
3-Open metadata overview file
6-Go to Tinderbox
7-Go to “THTG” parentNote
9-Delete Metadata overview in Devonthink
— Day 2- New files and you do the same step agin)

and also I have a lot of extra custom metadatas in Devonthink that I don’t want to import in Tinderbox. Therefore, The AppleScript will take less time if I get it to work correctly.

Given that the problem you’ve identified occurs in scripting DEVONthink do make sure to also ask in the DEVONthink forums as well as you may be able to access more scripting-related expertise related specifically to DEVONthink.

I would note—lest I appear to suggest otherwise—that @PaulWalters is an experienced DEVONthink user and his suggestion above draws on that expertise.

1 Like

Futher to my last here is a link to the DEVONthink automation forum which appears to be the sensible place to start asking at the DEVONthink end.

The script does have a lot of structural and flow issues, which I will not be taking the time to correct. However, posting to the DEVONthink forum, as @mwra suggests is the best medicine.