Timeout with performSmartRule

I’m trying to run this JXA script:

const app = Application("DEVONthink 3");
app.performSmartRule({name: "Resources: process inbox"});

But it does nothing, keeps Script Editor running and eventually gives a timeout. When applying this smart rule manually (with 1 item matched) it works without problems. Any ideas what could be going wrong?

(just tested, this also goes awry when using Applescript instead of JXA)

I don’t JXA, but just wondering why you have a space following name: but not following trigger: (you’ve just edited your post as I write).

Can you provide the AS you tested with, pls? I have used triggers like this in AS previously and am more likely to pick up a problem in AS than JXA.

Well spotted, but unfortunately the space does not seem to make a difference.

The same but in AppleScript:

tell application id "DNtp"
    perform smart rule name "Resources: process inbox"
end tell

Would it be possible for you to post the smart rule too?

It’s running an external JXA script which is quite complicated. I’ve tried with a simple rule to display an alert and that is showing… So possibly this rule does not run because it’s an external JXA script which is being called?

I know the feeling; most of my rules are complicated :smiley: Does the rule work if it is not called from a script but e.g. on import? What I am asking is whether it works but any means other than manually. There is (or was?) a difference between manual and triggered execution of rules as I noted here for example.

Yes, it normally triggers on import e.g. and other non-manual events. What I’m trying to do is make sure the rule runs at specific moment if through an external script. I’ve just tried to remove the “Execute script” action from the original rule and replace it with “Show alert” and then it works fine. Maybe @cgrunenberg could answer if there’s anything that could be happening because the smart rule is calling an external script?

FYI: Spaces are meaningless here, you can have as many or as few as you want.

Since you mention „timeout“ in the title of the post: You can set a timeout value when calling JXA functions. Apple’s JXA documentation mentions that (and I don’t remember the exact semantics), so you should be able to find it there.

If setting that doesn’t help, I’d suggest to pepper your 2nd external script with app.logMessage() calls or something similar so that you can at least get an idea up to which point it runs.

1 Like

Ah well; recognising patterns, clutching at straws :man_shrugging:t3: Thx for the feedback :+1:t3:

I’ve created a simplified JXA test script. It seems this has the same result: when I try to trigger the script via AppleScript or JXA with perform smart rule or app.performSmartRule() it gives a timeout (DT3.8.6). Wondering if you get the samen results with this @chrillek @blanc? Btw: it doesn’t seem to matter if it’s an internal or external JXA script.

function performsmartrule(records) {

	const app = Application("DEVONthink 3");
	app.includeStandardAdditions = true;
	app.logMessage("Starting Annotation Process incoming JS");
	app.showProgressIndicator("Processing incoming item", { steps: records.length, cancelButton: false });

	records.forEach(r => {
		app.stepProgressIndicator(r.name());
	});

	app.hideProgressIndicator();
	app.logMessage("Done Annotation Process incoming JS");
}

I can’t test before the end of next week, since I’m away from my Mac with the DT install.

However: Do you see any of the log messages?

No, none with the above script. As soon as it triggers it starts beachballing.

When trying with a rule which executes a simple inline AppleScript there are no problems:

on performSmartRule(theRecords)
	tell application id "DNtp"
		repeat with theRecord in theRecords
			log message "Test"
		end repeat
	end tell
end performSmartRule

Seems it’s definitely (another) JXA quirk?

For debugging purposes, this is what I have:

When trying to run this smart rule (with 2 items matched) e.g. via Applescript using

tell application id "DNtp"
	perform smart rule name "Resources: process inbox"
end tell

… it will beachball immediately, hold the whole app and eventually time out. It also seems very similar to this issue @Lynx was having a while back: Error "on performSmartRule (Error: Error: AppleEvent timed out.)" when running a smart rule wit a javascript script every minute - #13 by mdbraber

Thanks for persevering :+1:t3: I also cannot currently test; if it’s reproducibly beach balling though, that is excellent. Criss @cgrunenberg will ask you to sample the process and send him the result, and then - if past performance is any indication of future performance - he’ll come here and go “fixed for the next release” :slight_smile:

Thanks - I’ve send the debug logs to development@devontechnologies.com

Do you have other smart rules also targeting the Global Inbox?

No all other smart rules are disabled.

But are there any that target the Global Inbox, inactive or not?

There were others which targeted the same inbox as this rule (Resources > Inbox). None which targeted the Global Inbox. I’ve now removed all other smart rules and just kept this one. Restarted DT. Same result.