How to extract the 'Title' from 'More Info' Section of Get Info of PDF

I need to extract the Title from the More Info section of the Get Info window of a pdf. I would also like the pages and dimensions. I do not have acrobat but I have Adobe Reader 7.0.8. How do I extract this info using Applescript? I have a folder full of pdf’s for which I need this info in text form. Is this possible? I cannot find any applescript commands for Adobe Reader. Any suggestions really appreciated.

Model: MacBook Pro
Browser: Safari 419.3
Operating System: Mac OS X (10.4)

PDF Page Count

Using the same method as the page count, you can get the title (OS X v10.4+ only):

choose file with prompt "Get the title of this PDF file:" without invisibles
do shell script "/usr/bin/mdls -name kMDItemTitle " & quoted form of POSIX path of result & " | /usr/bin/grep -o '\".*$'"
set theTitle to text 2 thru -2 of result

You just saved me hours and hours of trying to figure this out. I am new to Applescript but would like to really learn it well since the few that I have created on my own have already saved a great deal of time in our workflow. Thanks a bunch!:smiley:

Model: MacBook Pro
Browser: Safari 419.3
Operating System: Mac OS X (10.4)

Perhaps this form would be better. I have lots of PDF files that have no title information:

choose file with prompt "Get the title of this PDF file:" without invisibles
try
	do shell script "/usr/bin/mdls -name kMDItemTitle " & quoted form of POSIX path of result & " | /usr/bin/grep -o '\".*$'"
	set theTitle to text 2 thru -2 of result
on error
	display dialog "Title not available for this PDF"
end try

Yes, it would be. :slight_smile:

You could aslo use error handling to set theTitle to an empty string (“”), false, etc.

I cannot get the whole script put together on my own. I am trying to get the name of the pdf, the title and the pages of all the pdfs in a folder and make a list in a text document that I can load into another system. I have spent hours (I am embarrassed to say how many) trying to piece together scripts to do this. I can get the filenames from a folder in a list in TextEdit but I don’t know how to incorporate getting the title and pages into that same document. Here is what I have to get the filenames of the folder:

tell application “Finder” to set filenames to name of every item of folder (choose folder)
set text item delimiters to ASCII character 10
tell application “TextEdit” to make new document at end of documents with properties {text:filenames as Unicode text}

Here is the piece to get the title (which I really don’t understand at this point):

choose file with prompt “Get the title of this PDF file:” without invisibles
do shell script “/usr/bin/mdls -name kMDItemTitle " & quoted form of POSIX path of result & " | /usr/bin/grep -o ‘".*$’”
set theTitle to text 2 thru -2 of result

I know I would have to add a tab delimiter in between the filename, title and pages which I think is ASCII character 9.

Is this possible or am I asking for way too much?

Model: MacBook Pro
Browser: Safari 419.3
Operating System: Mac OS X (10.4)

Something like this should work; However, I’m having problems with null bytes between characters.

choose folder "Get information for PDFs in this folder:"
tell application "Finder" to set thesePDFs to (files of (result) whose name extension is "pdf") as alias list

choose file name with prompt "Save information in this file:" default name "PDF Info.txt"
set outputFile to result

-- The output will start off as a list
set theOutput to {}
repeat with thisItem in thesePDFs
	set thisName to name of (info for thisItem without size)
	
	-- `mdls` is a command line tool to access Spotlight metadata information
	do shell script "/usr/bin/mdls -name kMDItemNumberOfPages -name kMDItemTitle " & (quoted form of POSIX path of thisItem)
	set thisMeta to paragraphs of result
	
	try
		set thisPageCount to text 24 thru -1 of (item 2 of thisMeta)
	on error
		-- A page count wasn't found
		set thisPageCount to ""
	end try
	
	try
		set thisTitle to text 24 thru -1 of (item 3 of thisMeta)
	on error
		-- This file has not title
		set thisTitle to ""
	end try
	
	set theOutput's end to (thisName & tab & thisTitle & tab & thisPageCount)
end repeat

-- Now the output is changed to text
set ASTID to AppleScript's text item delimiters
set AppleScript's text item delimiters to {ASCII character 10}
set theOutput to theOutput as Unicode text
set AppleScript's text item delimiters to ASTID

try
	open for access outputFile with write permission
	set fileRef to result
	
	write theOutput to fileRef
	
	close access fileRef
on error errMsg number errNum
	try
		close access fileRef
	end try
	
	display alert "Error " & errNum message errMsg buttons {"Cancel"} default button 1
	error number -128 -- Ensures that the alert cancels
end try

display dialog "Script finished!" buttons {"View Output", "OK"} default button 2

if (button returned of result) is "View Output" then
	tell application "Finder" to open outputFile
end if

:D:D:D

It works! Thank you so much!