Importing tags

Hi,

I have no real training in Applescript, but I’ve tried tweaked scripts before, and I’ve tried my best to make this thing work for me. So far I haven’t succeeded.

I’ve got a bunch of Web Archives I want to change to PDF without losing the tags. I’m happy to “re-download” the data from the URL contained in the Web Archive…in fact, that seems to be the most straightforward route. But I can’t figure out how to get the tags to transfer over.

Any ideas?

Here’s the code I’m working with (with my own failed contributions removed):


-- Convert URLs to PDF documents
-- Created by Christian Grunenberg on Mon Mar 23 2009.
-- Copyright (c) 2009. All rights reserved.

tell application id "com.devon-technologies.thinkpro2"
	set theSelection to the selection
	if theSelection is not {} then
		try
			set theGroup to display group selector
			show progress indicator "Converting..." steps (count of theSelection)
			repeat with theRecord in (the selection as list)
				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
					create PDF document from theURL referrer theURL name theName in theGroup with pagination
				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

Any guidance would be much appreciated!

This works

(*	Create a PDF from a webarchive and retain the tags of that web archive
	WARNING: this creates the PDF from a fresh capture of the content of the URL
	of the webarchive -- it does NOT convert the webarchive on disk to a PDF and
	so the resulting PDF may look different than the archive.  Results might
	be unexpected *)

tell application id "com.devon-technologies.thinkpro2"
	
	set theDatabase to current database
	set theSelection to selection
	set theGroup to display group selector
	
	repeat with thisItem in theSelection
		set itemURL to the URL of thisItem
		if itemURL begins with "http" then
			set itemTags to the tags of thisItem as list
			set newPDF to create PDF document from itemURL in theGroup
			set tags of newPDF to itemTags
		end if
		
	end repeat
	
end tell


Note the WARNING - the command "create PDF document from" in DEVONthink’s script dictionary downloads a fresh copy of the page content from the URL that is input to that command. This means that the resulting PDF will possibly have different content than the selected webarchive. The result of using this script might be unexpected. Also note that the execution of this script might be slow – execution depends on the responsiveness of the server from which you are capturing a fresh instance of the page, and on the normally slow PDF kit process of creating a document. The script will hang if your internet connection is down.

Hi korm,

I meant to thank you earlier. This script has been a big help!

@adro, that’s good news, thank you.