PerformSmartRule newly failing

For some reason I cannot figure out why the following is failing when triggered by a smart rule (as external scpt) and runs successfully when triggered from scriptdebugger, on the items in the smart rule view.

It seems it cannot perform the “get custom meta data” properly when triggered from the smart rule.

Was running well in 4.0 and 4.1, broke at some point. breaks when running 4.2.2.

Any idea?

use AppleScript version "2.4" -- Yosemite (10.10) or later

-- when calling on selection / single file
on run
	tell application id "DNtp"
		setThumbnails((selection of think window 1) as list) of me
	end tell
end run

-- when called by smart rule
on performSmartRule(theRecords)
	tell application id "DNtp"
		setThumbnails(theRecords) of me
	end tell
end performSmartRule

-- generic wrapper to handle multiple snapshots
on setThumbnails(theRecords)
	tell application id "DNtp"
		show progress indicator "Setting thumbnails ..." steps (length of theRecords) + 1
		repeat with theRecord in theRecords
			setThumbnail(theRecord) of me
		end repeat
		hide progress indicator
	end tell
end setThumbnails

-- record snapshotting
on setThumbnail(theRecord)
	tell application id "DNtp"
		set theType to (get custom meta data default value "" for "type" from theRecord) as string
		if (theType is equal to "book") then
			set color of theRecord to {26214, 14647, 455} -- book brown
		else if (theType contains "article") then -- also for article series
			set color of theRecord to {62450, 60392, 2523} -- article yellow
		else if (theType is equal to "person") then
			set color of theRecord to {50886, 12851, 65021} -- person pink
		else if (theType is equal to "organization") then
			set color of theRecord to {16190, 26985, 7709} -- org green
		else if ("course,event,session,workshop" contains theType) then
			set color of theRecord to {34437, 52686, 19789} -- event green
		else if ("podcast episode,video" contains theType) then
			set color of theRecord to {64847, 28802, 14389} -- video orange
		end if
	end tell
end setThumbnail

Did it definitely break after DEVONthink 4.2.2 or after upgrading to macOS 26.4? Does it work in the Script Editor.app or as an embedded script?

Why are you including the default value "" in this?

Also, you can’t apply color to documents, only tags and groups. Are you aware of this?

@cgrunenberg :

  • I am running macos 26.3.1 (a).
  • it works when run from the script editor.
  • it works when run from the scripts menu of DT (I copied it in the script folder for this test)
  • what’s an embedded script?

@BLUEFROG :

  • right, i dont need the default value, yet removing it does not change the issue
  • the smart rule is indeed applied to groups only ( I put my sources and notes about them in a same group).

In the smart rule, choose Apply Script > AppleScript then tap the Edit button.

I didn’t see any issue running your external script on demand, e.g., dragging and dropping the group on the smart rule.

The embedded script fails at the same point, returning a slightly different error (I wrapped the “set theType…“ line of code with two log messages “h1”, “h2” to ensure that the script is indeed failing on this line):

I tried dragging and dropping and it failed all the same.

TL;DR: it fails when run from a smart rule context, else passes.

I just successfully tested your script both using embedded and external scripts (macOS 26.4) in smart rules and batch configurations. For the test I used a group having the custom metadata type workshop.

Does it work after rebooting in safe mode? Is a verification of the database successful?

Database verified: all good.

Tested in safe mode : failed all the same.

Upgraded to Macos 26.4 : no more issues.

Case closed, thx everyone for the support.

Gremlins, ghosts in the machine, or Tahoe… :thinking: :slight_smile:
Thanks for the follow-up!