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.
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.
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
Thanks for persevering 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”
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.
It’s a timeout caused by one AppleEvent waiting for another one. The next release will include a workaround but actually it’s recommended to directly call the scripts in this case instead of indirectly via smart rules.
@cgrunenberg thanks for identifying the bug. I’ll check how I can run the script directly. Does this mean you’re actually advising against calling perform smart rule or app.performSmartRule() with smart rules running external scripts?
I forgot to add probably, but the timeout also happens when the smart rule is triggered by anything other than ‘on demand’ (same problem as @Lynx). So e.g. it also times out when “On import” is triggered because an item is added to the Inbox. So I’m eagerly awaiting the fix in the next release (or would there be a beta version to use / test)?
In that case it might be an issue of the used script and that it requires too much time for the default AppleEvents timeout of 60 seconds. Using a with timeout of x seconds ... end timeout block might fix this.