After reading some older posts here on the AppleScript method convert image
, I wrote a tiny little thingy in JavaScript:
function performsmartrule(records) {
var app = Application("DEVONthink 3");
app.includeStandardAdditions = true;
records.forEach (r => {
if (r.wordCount() === 0) {
const newRecord = app.convertImage (r, {record: r,
type: "PDF document", waitingForReply: false});
}
})
}
which does nothing but produce weird error messages:
- If I leave out the first parameter of
convertImage
, i.e.r
, I get a āmissing parameterā error - The same happens if I leave out the
record: r
part from the second parameter - If I call the method as shown above, I get an Error -1728, object canāt be found:
app = Application("DEVONthink 3")
app.selectedRecords()
--> [app.databases.byId(1).contents.byId(186284)]
app.databases.byId(1).contents.byId(186284).wordCount()
--> 0
app.convertImage(app.databases.byId(1).contents.byId(186284), {record:app.databases.byId(1).contents.byId(186284), type:"PDF document", waitingForReply:false})
--> Error -1728: Objekt kann nicht gefunden werden.
From the older posts, I concluded that in AppleScript the method would be called as
convert image record r
, without an unnamed first parameter (which goes against the description in the scripting library).
Bonus discovery: using app.ocr(r.path(), { file: r.path(), waitingForReply: true});
at least works, but also insists on using the fileās path twice. And of course it does not remove the original file after OCRing. On the other side, I donāt know if convertImage
would remove it, were it working as advertised.
Why do I even bother? Until recently, I had to use Hazel to watch a folder for incoming documents and change their names according to my wishes, since DT could not run JavaScript inside a smart rule. Now it can, and Iād like to get rid of the Hazel step, in analogy to