Scripting: How to add values to a custom column all at once?

I want to add values to a custom column in the same way the folder size shortcut updates the size values—processing files parallelly. So far I only managed to get my script to work by adding values to a item at a time.

In my case all the values for the items can be passed from an executable (it can handle the calculation parallelly) and therefor the values can be available at once. So is there a way to pass all those values to the custom column at once.

Folder size isn't calculated in parallel. (The bottleneck is the storage and filesystem, not adding the numbers up on the CPU, so requesting the information in parallel would be slower, at least on device types where it wouldn't be very fast via both methods.)

Scripts can use variables to store information if it has already been calculated and will be useful for another item. Either normal script-language global variables (which will persist until the script goes idle) or Opus vars (which can persist for longer, but probably don't make as much sense here). You can use those to store a cache of data and only re-calculate the information if the cache is empty, old, or doesn't have information for the requested file/folder.

What I'm trying to do is to create a word count custom column for text files that works faster than Column: Pandoc Word Count. I created a golang excutable that uses doctotext to output (either stdout or for temporary text file) the word counts of the files passed to it quickly.

For an example,


D:\TextBooks\Marijn Haverbeke\Eloquent JavaScript (635)\Eloquent JavaScript - Marijn Haverbeke\OEBPS\xhtml>dwc "bm01.xhtml" "bm02.xhtml" "bm03.xhtml" "bm04.xhtml" "ch00.xhtml" "ch01.xhtml" "ch01a.xhtml" "ch02.xhtml" "ch02a.xhtml" "ch03.xhtml" "ch03a.xhtml" "ch04.xhtml" "ch04a.xhtml" "ch05.xhtml" "ch05a.xhtml" "ch06.xhtml" "ch06a.xhtml" "ch07.xhtml" "ch07a.xhtml" "ch08.xhtml" "ch08a.xhtml" "ch09.xhtml" "ch09a.xhtml" "ch10.xhtml" "ch10a.xhtml" "ch11.xhtml" "ch11a.xhtml" "ch12.xhtml" "ch12a.xhtml" "ch13.xhtml" "ch13a.xhtml" "ch14.xhtml" "ch14a.xhtml" "ch15.xhtml" "ch15a.xhtml" "ch16.xhtml" "ch16a.xhtml" "ch17.xhtml" "ch17a.xhtml" "ch18.xhtml" "ch18a.xhtml" "ch19.xhtml" "ch19a.xhtml" "ch20.xhtml" "ch20a.xhtml" "ch21.xhtml" "ch21a.xhtml" "ch22.xhtml" "ch22a.xhtml" "copy.xhtml" "cover.xhtml" "ded.xhtml" "front.xhtml" "index.xhtml" "intro.xhtml" "nav.xhtml" "part01.xhtml" "part02.xhtml" "part03.xhtml" "title.xhtml" "toc.xhtml" "toc1.xhtml"
8671 14 220 330 60 3582 46 4770 52 4976 36 7131 54 3839 49 5315 36 3178 27 4663 45 6840 23 4399 16 6843 22 3607 28 2749 57 5419 35 5122 20 6574 12 6375 19 6722 49 5573 33 6080 54 4733 14 5705 19 445 1 4 244 40317 3207 4584 3 3 3 13 262 3856
D:\TextBooks\Marijn Haverbeke\Eloquent JavaScript (635)\Eloquent JavaScript - Marijn Haverbeke\OEBPS\xhtml>

What is the fasted method to add these values to the custom column?

Have you tried doing it the simple way first? It often turns out to be fast enough.

Unless the word-counting program has a lot of start-up overhead (which would be strange for something so simple), it isn't likely to matter if it's run once for all files or once per file.

PS: Please link your account.

I did it one file at a time. It's faster than using pandoc but it still took around 25 seconds or so for one of my folders that had about 60 text files. (pandoc one took 33 seconds). But it takes only second or two to get those values from the executable. I asked because the way folder size shortcut adds values really quickly was much better than what I'm seeing in my script right now, and to see if I could do it too.

Maybe using a cache would make sense, if the executable can't be made to run faster for individual files.

We can help if you link your account.

I don't think caching is necessary. I'm trying to do the calculation once (or few times as possible because the cmd max line length) for multiple files and store it in a temporary json file. Then I just have to read that json file once and col.method function can be made much simpler.

How can I access the file paths in the active tab (to pass multiple file path arguments to the executable like I showed in the example) before col.method function?

Have a look at https://www.gpsoft.com.au/help/opus12/index.html#!Documents/Codes_for_passing_filenames.htm
and use those when calling the exe.

Please link your account for continued support.

I managed to do it! Now it only takes a couple of seconds to add word counts for text files of the said folder. Now it works quickly just like how the folder size shortcut works! :smile: