Modified PDF Services Scripts

The PDF Services scripts included with DEVONthink Pro are clever enough to set the URL on the PDF record if printing from Safari or Mail. I’ve modified them to do the same if printing from the RSS aggregator endo or the web browser OmniWeb. Don’t use these versions unless you have those applications installed (or, as Christian of DEVONtechnologies reminded me, you’ll get a prompt asking to find the application). The scripts are easily modifiable to add the same feature for your favourite application (look for “this_app contains”). All the credit goes to the DEVONtechnologies team - I just added a couple of lines :slight_smile:

Save to DEVONthink Pro:


on open these_items
	set this_app to (path to «constant afdregfp» as string)
	if this_app does not contain "DEVONthink Pro" then
		try
			set this_file to item 1 of these_items
			
			tell application this_app
				try
					set this_name to the name of window 1
				on error
					set this_name to ""
				end try
				
				repeat while this_name is ""
					display dialog "Saving to DEVONthink Pro. Please enter a file name:" default answer this_name
					set this_name to the text returned of the result
				end repeat
			end tell
			
			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 theRecord to import this_file to theDestination
				try
					set the name of theRecord to this_name
				on error
					error "Import failed."
				end try
			end tell
			
			try
				if this_app contains "Safari.app" then
					tell application "Safari" to set this_url to the URL of document 1
					tell application "DEVONthink Pro" to set the URL of theRecord to this_url
				else if this_app contains "OmniWeb.app" then
					tell application "OmniWeb" to set this_url to the address of browser 1
					tell application "DEVONthink Pro" to set the URL of theRecord to this_url
				else if this_app contains "endo.app" then
					tell application "endo"
						if exists (selected article) then
							set this_url to the link of (selected article)
						end if
					end tell
					tell application "DEVONthink Pro" to set the URL of theRecord to this_url
				else if this_app contains "Mail.app" then
					tell application "Mail"
						set theSelection to the selection
						set this_sender to the sender of item 1 of theSelection
					end tell
					tell application "DEVONthink Pro" to set the URL of theRecord to this_sender
				else
					tell application this_app
						set curr_doc_path to path of document 1
						if (curr_doc_path is not missing value) and (length of curr_doc_path > 1) then
							set doc_url to "file://" & (POSIX path of curr_doc_path)
							tell application "DEVONthink Pro" to set the URL of theRecord to doc_url
						end if
					end tell
				end if
			end try
			
		on error error_message number error_number
			if the error_number is not -128 then
				try
					display alert "DEVONthink Pro" 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
		tell application this_app to activate
	end if
end open

Save to Printed:


-- The location of the destination group as a POSIX path ("/" is the top level of the database)
-- Replace desired / characters with \/
property pDestinationGroup : "/Printed"

on open these_items
	set this_app to (path to «constant afdregfp» as string)
	if this_app does not contain "DEVONthink Pro" then
		try
			set this_file to item 1 of these_items
			
			tell application this_app
				try
					set this_name to the name of window 1
				on error
					set this_name to ""
				end try
				
				repeat while this_name is ""
					display dialog "Saving to DEVONthink Pro. Please enter a file name:" default answer this_name
					set this_name to the text returned of the result
				end repeat
			end tell
			
			tell application "DEVONthink Pro"
				if not (exists current database) then error "Please open a database before using this script!"
				set theDestination to create location pDestinationGroup
				set theRecord to import this_file to theDestination
				try
					set the name of theRecord to this_name
				on error
					error "Import failed."
				end try
			end tell
			
			try
				if this_app contains "Safari.app" then
					tell application "Safari" to set this_url to the URL of document 1
					tell application "DEVONthink Pro" to set the URL of theRecord to this_url
				else if this_app contains "OmniWeb.app" then
					tell application "OmniWeb" to set this_url to the address of browser 1
					tell application "DEVONthink Pro" to set the URL of theRecord to this_url
				else if this_app contains "endo.app" then
					tell application "endo"
						if exists (selected article) then
							set this_url to the link of (selected article)
						end if
					end tell
					tell application "DEVONthink Pro" to set the URL of theRecord to this_url
				else if this_app contains "Mail.app" then
					tell application "Mail"
						set theSelection to the selection
						set this_sender to the sender of item 1 of theSelection
					end tell
					tell application "DEVONthink Pro" to set the URL of theRecord to this_sender
				else
					tell application this_app
						set curr_doc_path to path of document 1
						if (curr_doc_path is not missing value) and (length of curr_doc_path > 1) then
							set doc_url to "file://" & (POSIX path of curr_doc_path)
							tell application "DEVONthink Pro" to set the URL of theRecord to doc_url
						end if
					end tell
				end if
			end try
			
		on error error_message number error_number
			if the error_number is not -128 then
				try
					display alert "DEVONthink Pro" 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 if
end open