Perform smart rule trigger import event record not working

using this script

-- Mail Rule - Add attachments to DEVONthink
-- Created by Christian Grunenberg on Fri May 18 2012.
-- Copyright (c) 2012-2020. All rights reserved.

using terms from application "Mail"
	on perform mail action with messages theMessages for rule theRule
		tell application "Mail"
			set theFolder to (POSIX path of (path to temporary items))
			repeat with theMessage in theMessages
				set theSender to the sender of theMessage
				set theID to "<" & message id of theMessage & ">"
				set c to 0
				repeat with theAttachment in mail attachments of theMessage
					try
						if name of theAttachment ends with ".pdf" then
							-- if downloaded of theAttachment then
							set theFile to theFolder & (name of theAttachment)
							tell theAttachment to save in theFile
							tell application id "DNtp"
								set theAttachmentRecord to import theFile to incoming group
								set itemPath to path of theAttachmentRecord
								set theRecord to ocr file itemPath to incoming group with waiting for reply
								delete record theAttachmentRecord
								set URL of theRecord to "message://" & theID
								-- perform smart rule trigger import event record theRecord
								perform smart rule name "a smart rule" record theRecord
								set c to c + 1
							end tell
							-- end if
						end if
					end try
				end repeat
				if c > 1 then
					set theNotif to "Sent " & c & " PDF attachments to DEVONthink"
					display notification theNotif with title "Apple Mail"
					set read status of theMessage to true
					delete theMessage
				else if c = 1 then
					set theNotif to "Sent 1 PDF attachment to DEVONthink"
					display notification theNotif with title "Apple Mail"
					set read status of theMessage to true
					delete theMessage
				end if
			end repeat
		end tell
	end perform mail action with messages
end using terms from

if I uncomment the line perform smart rule trigger import event record theRecord and instead comment out the line with the specific smart rule (directly below), then the smart rule (see below) does not trigger. When I use the line which specifically names the smart rule, it does trigger. Any idea why?

DT 3.7 on macOS 11.3.

Does the record match the conditions? In case of a generic event…

perform smart rule trigger import event record theRecord

…the conditions are relevant but in case of a specified name they’re not:

perform smart rule name "a smart rule" record theRecord

yes it does match; if I select the smart rule, then the record in question is listed and if I apply the rule manually, it runs.

Oki doki, I’ve found a solution. In the original script, I was not performing OCR via the script, but with a rule which does OCR Apply on PDFs with 0 words. That rule does not contain a cancel action, but obviously “uses up” the on import trigger, so no further rules run. I was aware of that, which is why I triggered OCR from the script above, and then assumed I would be able to trigger the rules on the OCRd file using perform smart rule trigger import event record theRecord. I actually don’t understand why that doesn’t work.

My solution is to revert to the script as it originally was (that is without the OCR component). Then I added the following script to my OCR Apply rule in DT:

on performSmartRule(theRecords)
	tell application id "DNtp"
		repeat with theRecord in theRecords
			perform smart rule trigger import event record theRecord
		end repeat
	end tell
end performSmartRule

With that, my smart rule (which I posted above) runs correctly.

Ahhh, there’s an old bug cropping up here too; I’ve seen this one before.

one of the conditions was Content matches First I. Last - this will only trigger automatically if it is written Content matches "First I. Last"; the rule will happily run manually even if the condition is not enclosed in ". That will be why the import trigger didn’t run even when the document was already OCRd by the script in Mail.