This script used to rename the pdf as well as set the name in DP Pro. Now it sets the name in DP Pro, but sets the document name as “print job-#.pdf”. Not cool. How to fix this?
Script follows:
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 "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