Name dialog box for "Save to DEVONthink Pro" Scrip

I am looking for a way to print a document (usually in Safari) to pdf and (1) name the document, and (2) specify which group it is saved in. The fabulous Save to DEVONthink Pro script allows the user to select the group, but does not appear to allow me to name the pdf. So now, after I print the pdf into DEVONthink Pro, I have to switch to my database and rename the pdf.

I am wondering if anyone has figured out a way to modify this script so that it also allows you to name the pdf before it is sent to the database.

If this is not possible or necessary, are there any other clever methods of doing this?

Any help is greatly appreciated.

BTW: I imagine that this has already been addressed somewhere. However, despite my searching I have not yet found a resolution. I am sorry if this becomes a doublepost.

Open the “Save to DEVONthink Pro…” script in Apple’s script editor. Then just replace…

	set this_name to the name of window 1
on error
	set this_name to ""
end try


set this_name to ""


Thank you for the excellent fix. It doesn’t take long to fall in love with the scriptability of DEVONthink Pro.

For a quick follow up question: Is there any reason that I shouldn’t use this pdf services script when Safari (or another application) is already viewing a pdf. In another words, is it a bad idea to print a pdf to a pdf?

Is there a more elegant solution for importing a pdf that Safari has open into DEVONthink Pro with the option to select the name of the pdf and the group that it is important into in essentially one step?

Thanks again for your fix:


You could save this script in ~/Library/Scripts/Applications/Safari (and use it via the global Scripts menu extra):

tell application "Safari"
		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."
		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"
			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
	on error error_message number error_number
		if the error_number is not -128 then
				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

But it’s of course also possible to print PDFs to DEVONthink.

Thank you for the script. It works great. I wish that I could script like that. I have read a couple of books on Applescript, but I have never been able to figure out the syntax.