Save PDF from Safari in DT3

Continuing the discussion from Problem: Automating "Save PDF to DEVONthink 3":

I’m trying to create a script to save all open tabs in Safari as PDFs in DEVONthink 3 Pro and not having any success. When I use the AppleScript syntax linked above:

tell application id "DNtp" to create PDF document from theURL with pagination

I get an error:

URL of item 1 of {tab 1 of window id 2393, tab 2 of window id 2393, tab 3 of window id 2393} doesn’t understand the “create PDF document from” message.

When I try what seems to be the more current recommended syntax:

tell application id "DNtp" to create record with {name:name of theTab, URL:URL of theTab, type:PDF document}

… it appears to work correctly, with the clipper launched and a PDF document created with tags, URL & metadata - except the PDF is blank and zero bytes, and DT shows a PDF icon with “no file”. This is also true for .webarchive. This script syntax only appears to work if I save as type:bookmark

Any tips? Here’s the entire script in case it’s useful:

	tell application "Safari"
		set theTabs to tabs of window 1
		repeat with theTab in theTabs
			if exists URL of theTab then tell application id "DNtp" to create record with {name:name of theTab, URL:URL of theTab, type:PDF document}
		end repeat
	end tell

Incidentally, this issue frequently happens for me when I clip webarchives into DTTG and then sync to DT. The webarchives import and appear properly in DTTG but then show up as “no file” and 0 bytes in DT.

Solved my own problem. The issue was formatting syntax for the URL. Here’s the correct working script in case anyone else makes the same mistake as me!

tell application "Safari"
		set theTabs to tabs of window 1
		repeat with theTab in theTabs
			if exists URL of theTab then set theURL to URL of theTab
			tell application id "DNtp" to create PDF document from theURL
		end repeat
end tell
1 Like

I did time ago some similar, but only fo the active tab. It enables reading view and then makes the capture. It needs some help adding a keyboard shortcut in macOS settings. Perhaps you can combine with yours. This is the script:

tell application "Safari" to activate
tell application "System Events"
set target_process to 1st application process whose frontmost is true and visible is true
tell process "Safari"
	click menu item "Mostrar lector" of menu "Visualización" of menu bar 1
	delay 0.5
	tell application "System Events" to keystroke "p" using command down
	delay 0.5
	tell application "System Events" to keystroke "d" using command down
end tell
end tell

(Sorry, my Spanish keyboard does not have the inverse tick and it is very difficult to print).