JXA script using app.import() to `import` file to specific group

I am having difficulty with a simple JXA script to save a file to a specific group in DEVONthink. I have tried a number of very similar code snippets from this forum, all of which are said to work, but with no success for me in my environment.

I have trimmed the code down as much as possible to highlight the problem that I am having.

The code uses constants for the file name and the destination UUID, then tries to import the file to the destination group.

It looks to me like the import action is not behaving for me in the same way as it did for others but I can’t find any reference to any recent changes to the import interface.

Here is my JXA script:

dt = Application("DEVONthink");
const file = "/Users/paul/Downloads/Statements/Unknown.pdf";
const uuid = "C98D0C6F-DADB-4146-9D40-860287F63915";
const destGroup = dt.getRecordWithUuid(uuid);
console.log(destGroup.name()); //Statements, as expected
const record = dt.import(file, {to: destGroup}); //execution error: Error: Error: Message not understood. (-1708)

and here is what I see in the debug info from Script Editor

  1. Messages
/* Statements */
Result:
Error -1708: Message not understood.
  1. Events
app = Application("DEVONthink")
	app.getRecordWithUuid("C98D0C6F-DADB-4146-9D40-860287F63915")
	app.databases.byId(2).parents.byId(9464).name()
/* Statements */
app = Application("DEVONthink")
	app.import(["/Users/paul/Downloads/Statements/Unknown.pdf", {"to":app.databases.byId(2).parents.byId(9464)}])
Result:
Error -1708: Message not understood.
  1. Replies
app = Application("DEVONthink")
	app.getRecordWithUuid("C98D0C6F-DADB-4146-9D40-860287F63915")
		--> app.databases.byId(2).parents.byId(9464)
	app.databases.byId(2).parents.byId(9464).name()
		--> "Statements"
/* Statements */
app = Application("DEVONthink")
	app.import(["/Users/paul/Downloads/Statements/Unknown.pdf", {"to":app.databases.byId(2).parents.byId(9464)}])
		--> Error -1708: Message not understood.

I have spent hours making small changes but can’t make any progress. Hopefully someone can see my obvious coding error, or point out what I am surely missing about the import interface.

JXA doesn’t support synonyms contrary to AppleScript, the name of the command is importPath since version 4:

Just drag & drop DEVONthink 4 onto the Script Editor.app to view its complete script suite.

Thanks for the quick response. That fixed it, so now I can do some “real” work :wink: .

I’m feeling quite stupid. I am familiar with the dictionary in Script Editor, but didn’t realize that the there is an AppleScript/JavaScript/Objective-C drop down selector. Why would I, all my previous endeavors were with AppleScript, so I have been looking at:

the AppleScript version, and simply trying to infer the JXA equivalent. I did try importpath() at one point, but missed the Camel notation.

The entries are essentially the same, with ImportPath() also indicating a synonym (which is a little misleading), but there is no import() entry in the JXA version.

Thanks again @cgrunenberg !

1 Like