TextExpander Applescript to Retrieve DT3 Data

Thanks!
So this is on a Catalina or earlier machine, correct?

Just checking as Big Sur doesn’t show the tell current application dropdown. That’s what looked weird to me.

And also weird for your situation…


Works here, unzipped, opened, and run. :thinking:

Please try my code at your leisure…

const app = Application("DEVONthink 3");
const recs = app.selection();
for (let f in recs) {
console.log(`${recs[f].name()}`);
}

I had looked at other for loops, but as recs was reporting typeof = object, I approached it with the loop you see in my code.

Yes, arrays are objects. And JavaScript always returns this type for them. If you see list in the AppleScript dictionary, it’s an array in JavaScript. And records are objects proper. That is they do not provide the array methods.

Indeed. Thanks for the clarification.

[Sulking in embarrassment…]

It works!

The issue was indeed simply rebooting the computer.

Perhaps related - my system was so frozen on Apple News that it took a hard reset (powering down) to reboot the computer. Perhaps that is why the Javascript timed at in some trials. Not sure why Applescript worked when Javascript did not.

But in any event the JXA scripting is fully functional now - should be very interesting to try out some ideas for presenting data using Javascript.

Huge thanks to everyone who helped with this.

Woot! Reboot FTW!!! (And that’s For The Win, an MMO acronym, not the vulgar expression co-opted by the youth)

This simplified version works fine for me too:

const app = Application("DEVONthink 3");
const recs = app.selectedRecords();
console.log(recs.length);
for (let n in recs){
	console.log(recs[n].name());
}
2 Likes

Sure, that’s much simpler :see_no_evil:

Shhh… :wink:

1 Like

What is really simpler is this

const app = Application("DEVONthink 3");
const names = app.selectedRecords.name();
names.forEach(n => console.log(n))

Firstly, selectedRecords does not have to be enumerated to get to the individual properties, one can get the list of properties directly.

Secondly, for n in a; a[n]… is kind of „von hinten durch die Brust ins Auge“ (hopefully DeepL knows this one). Use forEach to iterate over an array if you do not need the indices. And even if you do need them, forEach is nicer because it gives you the array element and the index directly. No need for a[n].

1 Like

Halved the number of brackets & parentheses from 16 to 8 :wink: that is simpler :smiley:

1 Like
1 Like