'convert' applescript command broken

I’m trying to convert a group full of bookmarks to static HTML. logical I would use the convert record to html applescript command. Unfortunately, this is broken in DEVONthink Pro Office 2.9.10

Consider the following simple script:

tell application "DEVONthink Pro"
   set theSel to the selection
   repeat with theRecord in theSel
      convert record theRecord to text -- or rich text
   end repeat
end tell

The selection in DEVONthink Pro Office is a readable document, a note, anything, but DNtp simply returns ‘missing value’. What value am I missing?

The convert command isn’t broken. A Bookmark doesn’t contain convertible data. It is a pointer to a location containing data. Try looking at the verb create in DEVONthink’s AppleScript dictionary.

errrr…

The ‘convert’ command in DEVONthink works just fine on this type of content in the programme itself - just not in AppleScript.

If the content were not convertible, it could generate a more specific error that just ‘missing value’.

But that’s not the point. The point is, that the ‘convert’ AppleScript command doesn’t work on anything. Make a rich text document in the inbox a database, select it and run the code I posted earler. AppleScript simple beeps back, returning ‘missing value’.

I tried to make the command explicit by stating it should make the converted content in a specific group. But then the script fails to compile. The error it states then, is that the parameter is a property, not an object. A group (parent ‘X’ of database ‘Y’) is a property? Something is broken…

You said you were trying to convert a group full of Bookmarks. Bookmarks can’t be converted by a Convert command or AppleScript verb.

By the way…


convert record theRecord to text -- or rich text

There is no text or rich text option in DEVONthink’s AppleScript dictionary for the convert command.

[to html/‌note/‌rich/‌simple] : The desired format (default simple).

```are the options available.

irrespective of whether i am trying to convert a selection of bookmarks
irrespective of in what format i am trying to convert into

whether html or note or rich or simple

the convert command returns ‘missing value’

that is the point.

humour me and try the following:

select any rich text document in any database, and run the following script:

tell application id "DNtp"
    set myRecord to item 1 of (get the selection)
    convert record myRecord
end tell

…and tell me if this doesn’t return missing value…

Why not use –

tell application id "DNtp"
	set theURL to URL of the content record
	set theResult to create web document from theURL
end tell

and get WebArchives from your bookmarks? Works better than HTML for storage.

thanks for the suggestion, korm - if i can’t get convert to work likely i will end up doing that.

Actually, I did this on a previous project and this works fine. The only downside was that, because everything gets saved as a web archive (with all pictures and logos and extraneous stuff), the resulting database becomes quite large. The previous one was 12 GB and counting.

This is why I was looking to convert to html. I don’t necessarily need all the pictures and logo’s - the text, links and URL are fine. Storing this as HTML makes for a compact database (as in less than 5% of the size)

If you just want text (no images, etc.) then consider

tell application id "DNtp"
	set theURL to URL of the content record
	set theResult to create markdown from theURL
end tell

So, in the end, I wrote a little script that does the job – and found two more glaring bugs in DEVONthink’s AppleScript.

Here’s the script:

tell application id "DNtp"
	set myGroup to parent "XXX" of database "YYY"
	set myItems to children of myGroup whose type is bookmark
	
	repeat with myItem in myItems
		set myName to name of myItem
		set myURL to URL of myItem
		set myLabel to label of myItem
		set myState to state of myItem
		set myTab to open tab for URL myURL
		repeat while (loading of myTab = true)
			delay 1
		end repeat
		set mySource to source of myTab
		set myRecord to create record with {type:html, name:myName, source:mySource, URL:myURL, label:myLabel, state:myState} in myGroup
		--if myRecord ≠ missing value then delete record myItem
		close myTab saving no
	end repeat
end tell

What this does is take all the bookmarks from a particular group; get the name, URL, and other useful metadata; open the URL in a new tab in a new window; get the source from that tab; and create a new HTML record in the original group. The repeat loop with the delay is to allow the tab to load completely before capturing the source.

This works well. The only downside is the windows popping up beneath applications you are working in and the closing. But this has a reason.

I wanted the new tab to open in a viewer window of the current database, to prevent the popping up and popping away of all these windows. Unfortunately, that doesn’t work because of a bug in DEVONthink. If you do ‘open tab for … in window’, what is displayed momentarily is the correct content - but what is captured is the source of the previously openend tab, which then becomes the new content. In other words - you cature your first tab over an over again. DEVONthink creates the record with the correct URL, but the source does not match. By forcing DEVONthink to create a new tab in a new window, the correct source is captured.

You will see I have commented out a statement to delete the old record. Ideally, if a new record is created, the old one can be expunged. Here is the second bug. If you do that, somehow DEVONthink also put in the source of the new record you have just created the source of the previously created record. In other words – the same happens as above. The new record has the correct URL, but the source does not match. I’ve left the statement in, in the hope this gets fixed somewhere in the future.

Anyway, this works and for now I am a happy camper because at least the HTML content gets indexed. And, instead of having 24,000 records occupy 12 GB, it now occupies only 500 MB.