Passing variable from Applescript to Javascript for Acrobat 7 Pro

I just found this forum today and have already found some great information! However, I haven’t found a solution for my particular problem.

While I’ve done some work with AppleScript and javascript (separately), I’m new to using them to script Acrobat. I’ve written an AppleScript that, in part, needs to extract pages from a file. The extraction has to be done with javascript, as that function isn’t included in Acrobat’s Applescript dictionary. This javascript is called within the Applescript via “do script”. I’d like to be able to use an Applescript variable for part of extractPages “cPath” parameter.

The goal of the script is to allow users to split a PDF file into several smaller files. They specify the file to be split, the number of pages to include in each extracted file, and a text file containing a list of names to be used when saving the extracted files. Here’s the whole thing so far; it blows up when it hits the first extraction (error msg follows):


--** Splits selected PDF into individual files by extracting pages **

-- Prompt user for some stuff:
--** file to be split (convert to applescript reference so Acrobat can use it)
set splitting to (choose file with prompt "Open the PDF file to be split")
set splitting to POSIX path of splitting
set ASsplitting to POSIX file splitting as string

--** number of pages each chro spans
display dialog "Specify the number of pages each chro spans:" default answer "1"
set numPages to (text returned of result) as real

-- **file containing individual file names
set textfile to (choose file with prompt "Open text file containing filenames")

-- Get individual filenames from text file
tell application "TextEdit"
	open textfile
	set filenames to get every word of document 1
	close document 1
end tell
tell application "Finder"
	quit application "TextEdit"
end tell
set filecount to number of items in filenames

-- Figure out path to save files (new folder in same location as file to be split)
set temp to splitting
set i to offset of ":" in temp
set theFolder to ""
repeat while i > 0
	set theFolder to theFolder & (characters 1 thru i of temp as string)
	set temp to characters (i + 1) thru (count of characters in temp) of temp as string
	set i to offset of ":" in temp
end repeat
set theFolder to theFolder & "split_files:"
set theFolder to POSIX path of theFolder

-- Tell Acrobat to do the splitting
tell application "Adobe Acrobat 7.0 Pr#193E07"
	open file ASsplitting
	set pageCount to count of pages in splitting
	set startPage to 0
	set looper to 0
	repeat while looper < filecount
		set extractPath to (item (looper + 1) of filenames) & ".pdf"
		set endPage to startPage + numPages - 1
		do script ("
					// Extract pages to new pdf
					" & splitting & ".extractPages({
						nStart: " & startPage & ",
						nEnd: " & endPage & ",
						cPath: " & theFolder & extractPath & "
					});
					")
		set startPage to endPage + 1
		set looper to looper + 1
	end repeat
end tell

display dialog "Finished!" buttons {"OK"}

Error message:

I have not had any luck using a variable for the path. Can anyone shed some light on where I’ve gone wrong?
Thanks in advance!

Kristina

Model: G5
AppleScript: 1.9.3
Browser: Safari 312.6
Operating System: Mac OS X (10.3.9)