DT4b2 Bug(?) fixed in Script "Update Indexed items of all databases"

Whenever I run the script “Update Indexed items of all databases” (which ships with DEVONthink in the “Data” folder), I get the following error message:

DEVONthink got an error: AppleEvent handler failed.

This was working fine in DT3, but not in DT4. Not sure why, but with some help from ChatGPT, I was able to come up with something that works. I hope this works for others, and perhaps it would be good to update the default, if this is not just some idiosyncratic problem with my set up.

-- Set to true if indexed items are not only located at the root of the database
property pAllRecords : false

tell application id "DNtp"
	try
		set theDatabases to databases
		show progress indicator "Updating Indexed Items" steps (count of theDatabases)
		repeat with theDatabase in theDatabases
			step progress indicator (name of theDatabase as string)
			set theRoot to root of theDatabase
			set theRecords to children of theRoot
			repeat with theRecord in theRecords
				if pAllRecords then
					if indexed of theRecord is true then
						synchronize record theRecord
					end if
				else
					if indexed of theRecord is true and parent of theRecord is theRoot then
						synchronize record theRecord
					end if
				end if
			end repeat
		end repeat
		hide progress indicator
	on error error_message number error_number
		hide progress indicator
		if error_number is not -128 then display alert "DEVONthink" message error_message as warning
	end try
end tell

It’s an optional script installed via the support assistant. But you’re right, this one needs an update for version 4. Here’s an updated version, only two lines had to be changed:

-- Set to true if indexed items are not only located at the root of the database
property pAllRecords : false

tell application id "DNtp"
	try
		set theDatabases to databases
		show progress indicator "Updating Indexed Items" steps (count of theDatabases)
		repeat with theDatabase in theDatabases
			step progress indicator (name of theDatabase as string)
			set theRecords to children of root of theDatabase
			repeat with theRecord in theRecords
				if pAllRecords or indexed of theRecord then
					synchronize record theRecord -- Updates children of theRecord too
				end if
			end repeat
		end repeat
		hide progress indicator
	on error error_message number error_number
		hide progress indicator
		if the error_number is not -128 then display alert "DEVONthink" message error_message as warning
	end try
end tell
2 Likes

Thanks! I’d noticed this script was broken for DT4, but couldn’t for the life of me figure out why or where…