Hi,
I’m seeing infinite loading (beachball) in DEVONthink 4 beta 2 on macOS 15.4.1 when using a JXA script in a Smart Rule triggered by both ‘Before Synchronization’ AND ‘Every Minute’.
The script itself is simple:
function performsmartrule(records) {
const app = Application("DEVONthink");
app.includeStandardAdditions = true;
records.forEach(theRecord => {
theRecord.excludeFromSearch = true;
});
}
DEVONthink hangs when these two triggers are enabled together, requiring a Force Quit. Using other triggers works fine.
Is this trigger combination known to cause issues or possibly a bug? Thanks.
I’ve attached a 1-minute video showing this happen. The issue starts around the 0:45 mark.
https://player.vimeo.com/video/1081098593?h=cdb7d7e69c&badge=0&autopause=0&player_id=0&app_id=58479
Setting a smart rule to execute every minute doesn’t do anything useful except burn CPU cycles. Or send the program in lala land. Not to mention that excluding records from search over and over again might be a bit pointless, might it not?
If you really, really want to do that, I’d suggest something like this
function performsmartrule(records) {
const app = Application("DEVONthink");
records.filter(r => !r.excludeFromSearch()).forEach(r => {
r.excludeFromSearch = true;
});
}
You do not need standard additions unless you need them. And you do not need to exclude records from search unless they aren’t excluded yet.
What is even the point of that exercise?
Thanks feedback and the improved script
Actually my main intention was always just the ‘Before Synchronization’ trigger, which is sufficient. The ‘Every Minute’ trigger was added somewhat casually later on, mainly because that combination didn’t cause noticeable issues when I used AppleScript in the past
I also noticed that once the script excluded an item, that item often stopped matching my Smart Rule conditions anyway, so the script wasn’t repeatedly processing the same excluded items in my specific setup.
I posted about the hang because I was mostly just surprised that JXA caused a hang in this scenario where AppleScript didn’t seem to.
Anyway, I’ll remove the Every Minute trigger now. Thanks
How did the original AppleScript code look like?
Well, JXA is, as someone used to say, “a piece of crap”. I’d probably not go as far as that, but still … it’s unfinished and unpolished. The one thing it has going for it is that it provides all the current JS stuff like array methods, regular expressions, a Set
data type and so on. Probably no Promise
s, but I couldn’t care less for those.
As to the hang – I’m not convinced that that’s a JXA issue per se. Might be a race condition.
I don’t have the exact code anymore, but this is what I recall using in DEVONthink 3. It was likely a simple script like this:
on performSmartRule(theRecords)
tell application id “DNtp”
repeat with theRecord in theRecords
set exclude from search of theRecord to true
end repeat
end tell
end performSmartRule
It seems my earlier conclusion might have been slightly off. I removed the ‘Every Minute’ trigger and tested the Smart Rule with only the ‘Before Synchronization’ trigger enabled.
Unfortunately, DEVONthink still freezes (beachball) with just this single trigger active for the JXA script.
Interestingly, running the exact same JXA script using the ‘On Demand’ trigger works without any problems
Could this be an issue specific to DEVONthink 4.0 beta 2?
Some triggers like Before Synchronization have to await the completion of all actions (e.g. executing a script) and this works fine at least in case of AppleScript.
But JXA is different and has bugs galore, DEVONthink already contains several workarounds to make it more reliable. We’ll check this.
Following up on the JXA freezing issue
The JXA script freezing appears specific to the ‘Before Synchronization’ trigger. The same script work correctly with ‘After Synchronization’.
This isn’t isolated to one script; other JXA scripts with a similar structure also freeze when triggered ‘Before Synchronization’.
I can provide the JXA script if that would help your investigation.
1 Like
The script is not necessary, I was able to reproduce this. Unfortunately it’s not really possible to fix this (JXA has lots of flaws) but the next build will include a workaround at least.