This is my first post and my first time developing a script for Hazel.
I have a simple (short) JavaScript script that attempts to import a file into a specific group in DEVONthink 4. I am using it as an embedded script, so my understanding is that I do not need a handler and the file to process will be available to my script as theFile.
I have tested this script in Script Editor by simply adding a constant declaration to initialize theFile and it works as expected. Unfortunately it fails in Hazel.
Here is the script:
- Code: Select all
// Hazel script to move `theFile` to a fixed folder in DEVONthink.
const theID = "C98D0C6F-DADB-4146-9D40-860287F63915"; //JXA Test > Inbox > _Statements
// comment out the next line when running as an embedded JavaScript in Hazel
const theFile = "/Users/paul/Downloads/_Statements/Unknown.pdf";
//DEVONthink
const dt = Application("DEVONthink");
dt.includeStandardAdditions = true;
let params = {};
let destGroup = dt.getRecordWithUuid(theID);
params.to = destGroup;
const rec = dt.importPath(theFile, params);
This works as expected from Script Editor and the Replies window shows:
app = Application("DEVONthink")
app.getRecordWithUuid("C98D0C6F-DADB-4146-9D40-860287F63915")
--> app.databases.byId(2).parents.byId(9464)
app.importPath("/Users/paul/Downloads/_Statements/Unknown.pdf", {to:app.databases.byId(2).parents.byId(9464)})
--> app.databases.byId(2).contents.byId(9646)
Result:
Application("DEVONthink").databases.byId(2).parents.byId(9464)
However, when running the script in Hazel, the logs show:
2026-02-18 17:19:25.133 hazelworker[5482] DEBUG: Tapping error retry sequence
2026-02-18 17:19:25.134 hazelworker[5482] Unknown.pdf: Rule move to DEVONthink matched.
2026-02-18 17:19:25.134 hazelworker[5482] DEBUG: Manual run. Forcing actions to be executed.
2026-02-18 17:19:25.156 hazelworker[5482] [Error] JavaScript failed: Error executing JavaScript on file /Users/paul/Downloads/_Statements/Unknown.pdf.
2026-02-18 17:19:25.156 hazelworker[5482] OSAScript error: {
NSLocalizedDescription = "Error: Error: Can't get object.";
NSLocalizedFailureReason = "Error: Error: Can't get object.";
OSAScriptErrorBriefMessageKey = "Error: Error: Can't get object.";
OSAScriptErrorMessageKey = "Error: Error: Can't get object.";
OSAScriptErrorNumbe
rKey = "-1728";
OSAScriptErrorRangeKey = "NSRange: {0, 0}";
}
Most of the code runs in Hazel, including the getRecordWithUuid() call which returns the right result, until it fails with the final importPath() call.I know this, because I had instrumentation to log debug information to the DEVONthink log window, when running in Hazel, that I have since removed for simplicity to demonstrate the problem.
Consequently, I believe that it is the importPath() call that is generating the error messages seen in the Hazel log
As an aside, is there a way for me to log debug information to Hazel from my script - console.log() doesn't seem to work unless there is a switch that I need to set in the log window that I didn't notice.
Thanks in advance for any insight.