Hi everyone,
I’m encountering a strange context-specific issue with JXA scripts involving doShellScript in DEVONthink 4 beta 2 on macOS 15.4.1.
A JXA script using Application.currentApplication().doShellScript(…) to execute a simple curl command works perfectly fine when run directly from Script Editor. Furthermore, the same type of JXA script logic using doShellScript executes without issue when run as a Smart Rule action within DEVONthink.
However, when the exact same JXA script file used in Script Editor is placed in the DEVONthink Script Menu folder (~/Library/Application Scripts/com.devon-technologies.think/Menu/) and run from the DEVONthink Script Menu, the doShellScript call fails.
Test Script:
This JXA script demonstrates the issue.
(() => {
'use strict';
let resultMessageForAlert = "";
try {
const currentApp = Application.currentApplication();
currentApp.includeStandardAdditions = true;
const testCommand = "curl -s ifconfig.me";
const result = currentApp.doShellScript(testCommand);
resultMessageForAlert = `Success! External IP address is:\n\n${result}`;
currentApp.displayAlert("JXA doShellScript Test Succeeded", {
message: resultMessageForAlert,
as: "informational"
});
} catch (e) {
resultMessageForAlert = `Failure! An error occurred:\n\n${e.message || 'Unknown'} (Error Number: ${e.errorNumber || 'N/A'})`;
try {
Application.currentApplication().displayAlert("JXA doShellScript Test Failed", {
message: resultMessageForAlert,
as: "critical"
});
} catch (alertError) {
console.error(`Failed to display final error alert: ${alertError}`);
console.error(`Original error message: ${resultMessageForAlert}`);
}
}
})();
While this is a simplified test case, the way it calls currentApp.doShellScript(…) and the resulting error (-10004 from the menu) are exactly the same as in my original, more complex script.
Results:
Run from Script Editor: The script executes successfully and displays an alert with the external IP address.
Run from DEVONthink Script Menu… (Error Number: -10004)
Run as Smart Rule Action: The same logic works without privilege errors (tested with a more complex script).
Why would the exact same JXA script using doShellScript succeed when run from Script Editor and as a Smart Rule action, but fail with a -10004 privilege violation error only when run from the DEVONthink Script Menu?
Any help or insight would be greatly appreciated! Thanks.