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!
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 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.
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.