Add to DTpro all open tabs as PDFs script. Works but slow

I created a script to add all open tabs on DA as PDFs to a database in DTpro. My intention is to avoid having to use repeatedly the menu Data-Add To Devonthink-PDF (paginated or not) and move from tab to tab. Specially when dealing with tens of them. The following script works but not as I would like it to work:

tell application "DEVONagent"
	set theTabs to tabs of window 1
	repeat with theTab in theTabs
		set theURLoftheTab to URL of theTab
		if exists URL of theTab then tell application "DEVONthink Pro" to create PDF document from theURLoftheTab
	end repeat
end tell
  1. My script takes longer (seconds) to create the PDF when compared to the build-in option under the Data menu. The PDF layout is also different. How can I improve my script to speed up the capture of the PDF for each open tab?

  2. For each tab it will ask me where to put it into the database. Handy in some cases, but is there a way to make the script send all PDFs to the same location without having the ask each time?

Thanks.

The “create PDF document from” has to download & render the page again. But you could use the PDF or paginated PDF property of tabs, e.g.


tell application "DEVONagent"
	set theTabs to tabs of browser 1
	repeat with theTab in theTabs
		set theURL to URL of theTab
		set theName to name of theTab
		set theData to PDF of theTab
		tell application "DEVONthink Pro"
			set theRecord to create record with {name:theName, type:PDF document, URL:theURL}
			set data of theRecord to theData
		end tell
	end repeat
end tell

You could use the “display group selector” command and use the returned value for the create command’s “in” parameter.

The script that you created worked perfectly! Thanks.