AppleScript: creating records with get cached data not working?

Hello,

I just dusted off an old script that I posted many moons ago in this thread: DevonAgent/Devonthink provide DOM list via JavaScript

It doesn’t seem to work in DEVONthink 3 and I cannot figure out why. It looks to me that both with my script and Christiian’s devonthink says it is creating records from the data, but then the records are not appearing? It looks like the Javascript command is firing, and that it is querying the DOM, but either the data string that it is returning is invalid, or the cached data isn’t plugging into the create records command correctly. Either those things or I’ve just forgotten how to do this. Any help would be appreciated.

Sorta related: am I misremembering or did Devonthink Pro once upon a time allow one to open up webkit’s “inspect element” and query the javascript console? In this instance (I’m trying to harvest images from web searches with a AppleScript command) it would be very useful to query the DOM with javascript and use its tools for doing this.

As always, thanks again for Devonthink…I’ve been a user since the very first versions…still love it!

best,
Erico

further investigation here makes me think that the doJavascript command doesn’t return correct values back some of the time in Devonthink 3. If I go to a books.google.com page and send a “do JavaScript “document.getElementsByClassName(‘addmd’)[0].childNodes[0].data” in document window id xxxx” it comes back with a null string in Dt Pro 3. Safari gives me the right answer, which is the author’s name.

am I misremembering or did Devonthink Pro once upon a time allow one to open up webkit’s “inspect element” and query the javascript console?

Nope. DEVONagent Pro does in its browser. DEVONthink never has (I know, because I’ve asked about it in the past.)

In this instance (I’m trying to harvest images from web searches with a AppleScript command) it would be very useful to query the DOM with javascript and use its tools for doing this.

@cgrunenberg would have to assess this and the Inspect Element option.

If I go to a books.google.com page

Do you have a specific URL to share?

As always, thanks again for Devonthink…I’ve been a user since the very first versions…still love it!

Glad to hear it! :slight_smile:

That’s actually handled by the WebKit, not by DEVONthink. What is returned in Safari and what’s the URL?

Here’s an example URL:
https://www.google.com/books/edition/Critique_of_Pure_Reason/7UCbAAAAQBAJ?hl=en&gbpv=1&dq=critique+of+pure+reason&pg=PT17&printsec=frontcover

If I go to the Javascript console in Safari and type in this:
document.getElementsByClassName(‘addmd’)[0].childNodes[0].data

I get.

“By Immanuel Kant” = $2

In Devonthink 3 creating a URL, opening it and running the script:

tell application “DEVONthink 3”
set theWindow to think window 1
set cnt to (do JavaScript “document.images.length” in theWindow) as integer
set author to (do JavaScript “document.getElementsByClassName(‘addmd’)[0].childNodes[0]” in theWindow)
end tell

Yields a proper integer for the first query, but a null string ("") for the second

I indeed cannot get it to return any valid strings that are replies to functions—urls or code. Code that used to work to do this no longer does. If I had to guess, the problem looks like it is not converting a data type correctly, perhaps into unicode or something like that.

Thanks for taking a look

Erico

Maybe DOM trees are not identical in Safari & DEVONthink (different user agents, different WebKit versions) as this document.getElementsByClassName('addmd') seems to return an empty list.

yeah, I’m not seeing anything come back…regardless of the shape of the DOM.

Querying for instance the active element gives me a null string:

tell application “DEVONthink 3”
set theWindow to think window 1
set activeelement to (do JavaScript “document.activeElement” in theWindow)
end tell

“document.all” also gives nulll string, while safari behaves as expected…

Maybe a regression/change of the latest WebKit and/or macOS versions (Safari does not use the public WebKit API).

would it be helpful for me to try to figure out when the regression happened by testing it under older devonthink / system versions?

If you’re so inclined, that may be useful :slight_smile: