I’m trying to write a JXA script which sets the data of a PDF record - unfortunately neither createRecordWith({name:"Test", data:data}) nor r.data = data works.
app = Application("DEVONthink 3");
records = app.selectedRecords();
records.forEach(r => {
// Create a new PDF record with the data from the current record
app.resultRecord = app.createRecordWith({name:"Test", type:"PDF document", data:r.data()});
});
When I use this on a selected PDF record Script Editor gives ‘Error -50: Parameter error’ and pops up an “Invalid argument data” error. When trying to set r.data = data for a record r with other scripts no data is set at all. This method does work in AppleScript.
Any clues on how this should work? Or is the data property broken in JXA?
Side note: I noticed that on the createRecordWith function in the Dictionary it incorrectly mentions creation and modification as arguments, which are wrong as they should be creationDate and modificationDate so maybe something is going wrong with the AS-JXA translation here (as well)?
@cgrunenberg would have to comment on that. But I seem to remember that data returned some hex encoded data, eg for images. Never figured out how to get actual data from it.
Just to clarify: if, for example, I have a jpeg image in DT, data would be the binary content of this image in AppleScript? And in JS I’d get some kind of hex ascii which should be equivalent to the binary data?
I’m asking because then it just might be possible to en/decode the stuff in JS. Perhaps.
@cgrunenberg that’s what I’m trying here, but gives me a Parameter error as described above. Do you mean you have this working in your internal builds for the next release?
Great. Another one added to my things-to-look-forward to in the next release.
Just curious if you’re willing to collaborate, why wasn’t it working? I always understood AppleScript → JavaScript was an automatic translation so there wasn’t much to do if it wasn’t working?
It is but unfortunately it has a bunch of its on flaws & bugs (and doesn’t get much love from Apple). In the meantime you could of course use AppleScript which works flawlessly