JXA - Are Sheet Headers Cached?

Hi all

As I said before I’m using DT as file storage/management for a website I’m working on. Unconventional but it works perfectly for what I’m trying to do. I’m writing a JXA script to verify my files before export - it should iterate given group and its files, checking that certain files are present, and for some sheets check that the correct columns are in the file. Should be a simple enough case of looping over the names and comparing them, but what do I know!

Loading the files is fine but when I try to compare a certain sheet’s columns to confirm they’re all present, it seems to load an old version of the file’s headers, maybe the ones which were initially created.

I’ve loaded the sheet’s columns using sheet.columns() and when I open a debugger the column names don’t match what DT shows, nor what I can see when I open the sheet in a text editor.

Are column name cached somewhere by DT, and if so is there a way for me to force an update of this?

Many thanks

DEVONthink uses indeed a cache internally but this is e.g. updated after editing the sheet. How did you edit the sheet after adding it to the database? Via JXA? Or did you edit it with another app?

Another app; a python script actually as I’d dozens of files to change but didn’t realise this would be an issue. When I could visually see the changes had been made, what I thought was correctly, it didn’t occur to me that this would crop up.

If I rebuild the database, I assume that the item links are changed?

Rebuilding retains the UUIDs and therefore the item links.

One last annoying question: is there any method of adding/editing columns with either AppleScript or JXA? Looking at DT’s dictionary in the Script Editor, it says that the column field of a record is read-only so while I assume this is correct, I’m hoping that I’m missing something!

But the cells property doesn’t seem to be. You could get those, append a value to each of the rows, and then set the cells property again. Not particularly elegant, but perhaps feasible.

Make sure that the new values are strings.

Edit Oh well, it looked promising. But apparently, columns is what fixes everything. So, there’s a set of columns, and if one adds to a row of cells, nothing happens. No luck there. Also, there doesn’t seem to be a way to create a table programmatically, which makes creating a new table and populating it with the data from the old one a no-go, too.

Which makes me believe that the short answer to your question is “no”.

1 Like

That’s of course possible, see e.g. script Add abstract to DEVONthink for DEVONagent (see ~/Library/Scripts/Applications/DEVONagent).

The columns can’t be changed. However, due to a bug the cached value which is only used by AppleScript wasn’t updated after external editing, neither automatically after filesystem events nor manually by using File > Update (Indexed) Items. The next release will fix this.

1 Like

Oh amazing. I was in the middle of writing a JXA script to create a new sheet and copy the data over, so there is no need to do this then? I’m currently trying to create a new record (sheet) but am struggling to create it in a specific group using createRecordWith, atm it just creates it in Inbox

Edit: Figured it out, so for posterity here it is in case anyone else ends up here:

app.createRecordWith({"name": "name", "type": "sheet", "columns": ["a", "b", "etc"]}, {in: <group>});
1 Like

At least if it’s not urgent for you.

Most likely either the in parameter is missing or invalid.

1 Like

Yeah I had the in parameter incorrect. I put working code above in case anyone else ends up here; didn’t realise it needed to be in braces.

Thanks for all the help

1 Like