Acrobat/Applescript confusion

I’m writing a script to combine pdf files from a user selected folder into a new pdf file. A blank page will be inserted after each pdf in the new file. I need to count the pages in each pdf before I insert it into the combined file.

After the user choose the folder with the pdfs that are to be combined I’m stepping thru the list of pdfs to open each one, get the page count and insert it into the new combined pdf file.

Here’s how I’m getting the files from the file list:

tell application id “com.adobe.Acrobat.Pro”
set currentDoc to item 1 of fileList
open currentDoc
set pageCount to count pages of currentDoc
close currentDoc saving no
end tell

However that generates an error:
“Can’t make «class docf» "Alcott, Thomas LOI 20-6N-5W.pdf" of «class cfol» "Echo Batch" of «class cfol» "Desktop" of «class cfol» "rjay" of «class cfol» "Users" of «class sdsk» of application "Finder" into the expected type.” number -1700 from «class docf» “Alcott, Thomas LOI 20-6N-5W.pdf” of «class cfol» “Echo Batch” of «class cfol» “Desktop” of «class cfol» “rjay” of «class cfol» “Users” of «class sdsk»

But if I replace my variable “currentDoc” with “active doc” as in:

tell application id “com.adobe.Acrobat.Pro”
set currentDoc to item 1 of fileList
open currentDoc
set pageCount to count pages of active doc
close active doc saving no
end tell

everything works as expected.

Obviously I’m not understanding how my variable “currentDoc” is handled by AppleScript. Acrobat opens the file referred to by the variable, but apparently can’t do anything else to that file if I refer to the variable rather than Acrobat’s “active doc” property. Any illumination on this would be appreciated and probably help my scripting ability immensely.

Model: iMac
AppleScript: 2.4
Browser: Safari 600.6.3
Operating System: Mac OS X (10.10)

Hi,

the main issue is that currentDoc is obviously a Finder object specifier and is later treated as an Acrobat document specifier. This cannot work.

From my experience the most reliable way working with multiple documents in Acrobat is to reference each document by its name rather than using the active doc property


-- assuming fileList is a list of Finder object specifiers
tell (item 1 of fileList) to set {fileName, filePath} to {its name, it as text} -- this even works outside a Finder tell block
tell application id "com.adobe.Acrobat.Pro"
	open filePath
	set currentDoc to document fileName
	set pageCount to count pages of currentDoc
	close currentDoc saving no
end tell


Excellent! That works perfectly. And your explanation helped a lot.
Thanks so much.