Saving PDF from Safari directly to DTP

I’ve scanned the forum but couldn’t find an answer to what may have an obvious response:
Frequently I access PDF documents via Safari and these are displayed in Safari via a PDF viewer plug in. The address line shows the link back to the pdf document. Currently, the only way I can figure out to get the document into DTP is to save it to my hard drive and then import it. None of the scripts seem able to deal with this situation. Dragging the link just provides a link back to the doc, but the danger there is that the link may expire or the document is removed from the original site.
Thanks
Nestor

I’ve gone to selecting the URL in Safari and then using the service to open the URL in Devon Agent. From there I can send it to DTPRo.

Works if you have DA, but I think a script or automator process would be nicer, yes far nicer.

Francis

Thanks for your reply. However, I don’t have DA (just DT Pro). Furthermore, what you’ve described is a two-step process, just a different two steps than what I’m doing. Glad you agree a more direct approach would be preferable! Maybe we start a movement to get it included in the product.
Nestor

Here’s a script to add a PDF from Safari (visible in the frontmost browser window) to DEVONthink Pro (just save this script to ~/Library/Scripts/Applications/Safari and use it via the global script menu extra):


tell application "Safari"
	try
		if not (exists document 1) then error "No browser is open."
		set theURL to URL of document 1
		if theURL is missing value or theURL is "" then error "No page loaded."
		if (theURL does not contain "pdf") and (theURL does not contain "PDF") then error "No PDF loaded."
		
		set this_name to ""
		repeat while this_name is ""
			display dialog "Saving PDF to DEVONthink Pro. Please enter a file name:" default answer this_name
			set this_name to the text returned of the result
		end repeat
		
		tell application "DEVONthink Pro"
			activate
			if not (exists current database) then error "Please open a database before using this script!"
			set theDestination to display group selector "Destination" buttons {"Cancel", "OK"}
			set thePDF to download URL theURL
			set theRecord to create record with {name:this_name, type:picture, URL:theURL} in theDestination
			set data of theRecord to thePDF
		end tell
		activate
	on error error_message number error_number
		activate
		if the error_number is not -128 then
			try
				display alert "Safari" message error_message as warning
			on error number error_number
				if error_number is -1708 then display dialog error_message buttons {"OK"} default button 1
			end try
		end if
	end try
end tell

Terrific! Thanks very much.

When I try to use this script to save a pdf viewed in Safari with the Adobe plugin, I get this error:

variable v_rec is not defined

It does not save to DTPO.

Any ideas what is wrong?

thanks

It’s intended for PDF documents displayed by the default viewer of Safari/Mac OS X.

I’ve confirmed that the Adobe PDF plugin conflicts with WebKit-based browsers such as DEVONagent and DT Pro’s browser. The plugin for Adobe Reader 8 seems worse than earlier versions. I was sometimes unable to view a PDF document in DT Pro.

Advice: Remove the Adobe plugin for viewing PDFs in browsers. It’s not necessary anyway if you are using OS X 10.4.x for Safari and WebKit-based browsers. Apple’s PDFKit does fine, unless the Adobe plugin is present.

Again,

The advice of a Sage (or two) saves the day

:slight_smile:

I tried the script given above in DTP 1.5.1 and Safari 3.1 but it didn’t work. Instead of a PDF in DTP, I get a thumbnail image of the first page, but not the actual PDF file. Is there a workaround for direct import of PDFs in the browser window?

This is unfortunately a bug of the lastest version’s scripting. The next maintenance release will fix this.