Script to automatically set name of PDF

Hi,

this little script (with much help of pdf inspector http://www.docear.org/software/add-ons/docears-pdf-inspector/) extracts the title of each pdf and sets the names of the selected records. should skip selected non-PDFs.

tell application "DEVONthink Pro"
	try
		set inspector_path to "~/bin/docears-pdf-inspector.jar"
		set this_selection to the selection
		if this_selection is {} then error "Please select some contents."
		set giveOutput to true
		
		repeat with this_item in this_selection
			set filePath to get path of this_item
			set prevName to get name of this_item
			
			set oldType to get type of this_item
			
			if oldType = PDF document then
				set cmd to "java -jar " & inspector_path & " -title " & quoted form of filePath
				set newName to (do shell script cmd)
				set name of this_item to newName
				if giveOutput = true then log message "Set name for '" & prevName & "' to '" & newName & "'"
			else
				if giveOutput = true then log message "Skipped setting a new name for '" & prevName & "' because it is not a PDF."
			end if
		end repeat
	on error errtext
		display alert errtext
	end try
end tell

Might be helpful to some. Pdf Inspector generally does a good job, according to their website its 70%. it works really well on academic papers.

cheers.

Clever 8) Thanks, also, for the reference to Docear

I am probabky doing something wrong as I do not really understand scripts so please forgive me if I have got this entirely wrong :blush: I saved this script into my DTPO Scripts>Data folder and then selected some items and run the script. I got the error message as below. Any help to sort out what I have done wrong would be much appreciated. Thanks.
01.jpg

allsop,

this script requires a third-party ‘application’, the link (http://www.docear.org/software/add-ons/docears-pdf-inspector/) included in the first post. it is open source and free.

at the bottom of the page there is a section ‘Develop & Download’. it gives you a direct link to the zip archive. download the zip archive (http://docear.org/download/docears-pdf-inspector.zip) to your disk and extract it. you should see a new directory with two files:

docears-pdf-inspector.jar
readme.txt

the jar file is the important file the script needs. put the jar file somewhere where you dont need to move it later again and/or have to delete it. you could probably even copy it into your “DTPO Scripts>Data folder”.

get the path to the jar file, including the filename. in the script you have a line (third line)


set inspector_path to "~/bin/docears-pdf-inspector.jar"

change that to


set inspector_path to "yourpath/docears-pdf-inspector.jar"

if you copy it to the data folder, it should be


set inspector_path to “~/Library/Application Support/DEVONthink Pro 2/Scripts/Data/docears-pdf-inspector.jar”


save it. done.

a bit of caution though: dont just run it on all your files. try it on one and see if you like it

Thank you bosie :smiley:

hope it works for you.

new version up that makes the non-pdf skipping explicit and lets you decide if you see a log entry or not per file.