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."
		return
	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"
		else
			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
			activate
			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 ?

Did you try running the script in script editor and follow the stream of events? That might tell you something.
Also, it’s recommend to user selected records instead of selection

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.

I think that’s a problem with Tinderbox, not DT.

1 Like

You should not be using the same alias on multiple files.

the note will be missing data

What data - all of it, some of it, one attribute?

for no reason

There is always a reason. :wink: