Script to convert DT bookmark to DT web archive??

Does anyone know of a script that I can use to convert one or more selected bookmarks in DT into a web-archive?

Have you tried from the Scripts menu:

Download->Create Offline Archive

That doesn’t work…

Any other thoughts?

This script supports all selected contents having a URL, not only bookmarks:


tell application "DEVONthink Pro"
	set theSelection to the selection
	if theSelection is not {} then
		try
			activate
			show progress indicator "Downloading..." steps (count of theSelection)
			repeat with theRecord in theSelection
				set theName to name of theRecord
				step progress indicator theName
				if exists URL of theRecord then
					set theURL to URL of theRecord
					if theURL begins with "http:" or theURL begins with "https:" then
						set theData to download web archive from theURL
						if exists parent 1 of theRecord then
							set theGroup to parent 1 of theRecord
						else
							set theGroup to missing value
						end if
						set theArchive to create record with {name:theName, URL:theURL, type:html} in theGroup
						set data of theArchive to theData
					end if
				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

AWESOME!!

That works perfectly!! Thanks so much for your help…it’s much appreciated!

I have a large collection of bookmarks I would like to convert to web archives. When I use Christian’s script on a selection of bookmarks in DTPO 2 I get blank HTML documents named with the name of the original bookmark. The script Download > Create Offline Archive doesn’t appear to do anything (perhaps it puts its output somehwere not obvious?) Thanks.

I’m not an AppleScript expert, but maybe the following script works for you. I just modified the aforementioned script a little.

tell application "DEVONthink Pro"
	set theSelection to the selection
	if theSelection is not {} then
		try
			activate
			show progress indicator "Downloading..." steps (count of theSelection)
			repeat with theRecord in theSelection
				set theName to name of theRecord
				step progress indicator theName
				
				if exists parent 1 of theRecord then
					set theGroup to parent 1 of theRecord
				else
					set theGroup to missing value
				end if
				
				if exists URL of theRecord then
					set theURL to URL of theRecord
					create web document from theURL in theGroup name theName
				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

Perfect. Works just as I would hope. Thanks! :stuck_out_tongue:

[size=75](One caveat that has nothing to do with your work - if the bookmark points to a URL that is a PDF, then nothing is returned. As expected. However, there seems to be a bug (which might be due to the latest version of Adobe reader) that causes DTPO to crash when it is opening bookmarks pointing to PDFs. After 10 crashes in a row, I can confirm this is repeatable :confused: and has been submitted on a bug report to DT.)[/size]

For me the script returns a 0 byte html file, displaying a blank page. Wonder if it’s a Devonthink 2.0 issue, which I am using.

Actually the script requires v2.0 and is working fine over here. What’s the URL of the page you’re trying to convert?

This is a tremendously useful script, but I’m wondering what it would take to output markdown (with readability) instead of a web archive?

Just replace the “create web document from” command with “create Markdown from” and add the parameter “using Readability” if desired.