Convert bookmarks into html pages

I keep a lot of clippings as bookmarks only – it’s faster and it saves space. But what if I want to convert these into web pages, in case the links go dead, or so I can search the contents? I could load them each separately and save them. Or I could use this script I’ve written:

tell application "DEVONthink Pro"	
	set theSelection to the selection	
	repeat with thisItem in theSelection
		set thisPage to convert record thisItem to html
		set theUrl to the URL of thisItem
		set theSource to download markup from theUrl
		create record with {name:thisPage, type:html, source:theSource, URL:theUrl} in current group
		delete record thisItem
	end repeat
end tell

Shouldn’t the line “set thisPage to convert record thisItem to html” be “set thisPage to name of thisItem”? Because converting bookmarkls to HTML via the “convert record” command isn’t possible.

“Because converting bookmarkls to HTML via the “convert record” command isn’t possible.”

Except it is. Have a try: it works!

“convert” only seems to work if the bookmark’s content is already in DevonThink’s cache. If you select a lot of bookmarks and try to run through them all, the ones that haven’t been loaded before will fail.

I’m also converting a lot of bookmarks from my browser to DevonThink, and I wanted the page text so they can be indexed, searched, and categorized. An HTML version often avoids the size of full web archives while preserving more typography than a markdown version.

[size=85]```
– Convert URLs to HTML documents
– Created by Rocco Caputo on Mon Apr 4, 2016.
– Based on information gleaned from the DevonThink
– forums and the script “Convert URLs to PDF documents”
– Created by Christian Grunenberg on Mon Mar 23 2009.
– Copyright © 2009-2013. All rights reserved.

tell application id “com.devon-technologies.thinkpro2”
set theSelection to the selection
if theSelection is not {} then
try
show progress indicator “Converting…” steps (count of theSelection)
repeat with theRecord in theSelection
set theName to name of theRecord
set theURL to URL of theRecord
step progress indicator theName
if theURL begins with “http:” or theURL begins with “https:” then
set theGroup to parent 1 of theRecord
set theSource to download markup from theURL

				set theCopy to create record with {name:name of theRecord, type:html, source:theSource} in theGroup
				
				set URL of theCopy to URL of theRecord
				set tags of theCopy to tags of theRecord
				set comment of theCopy to comment of theRecord
				set aliases of theCopy to aliases of theRecord
				set date of theCopy to date of theRecord
				set creation date of theCopy to creation date of theRecord
				set label of theCopy to label of theRecord
				set state of theCopy to state of theRecord
				
				-- Last, just to be sure.
				set modification date of theCopy to modification date of theRecord
				
				-- Uncomment to delete the original.
				-- delete record theRecord in theGroup
			end if
		end repeat
		hide progress indicator
	on error error_message number error_number
		hide progress indicator
		if the error_number is not -128 then display alert "DEVONthink Pro" message error_message as warning
	end try
end if

end tell