Vanishing file

Hey all,
I have script that splits multi-page PDF files into individual pages. This worked great with 9.2. I had to rewrite some stuff for 10.3.4, which was ok. However, there is a part of the script that tells the finder to select a blank PDF that the script creates in order to duplicate it. As I step thru Script Debugger, I notice that the blank PDF disappears for an instant when the script selects it. That causes the script to not be able to find the file and it chokes. Sometimes when I run the script from Script Debugger, it will run OK, but if I save it as an app and try to run it, it will fail. Weirdness.
I’ve noticed that the Finder doesn’t seem to like being talked to by Applescript. Any input would be helpful.
Thanx,
mike

Hi again, Everyone!
k. My bad. I should’ve posted the code that’s causing me grief.
This script was created by a person named David Wadson. I tweaked it a bit to make it fit my needs. So, thanx again to David.
Like I said in the earlier post, this seems to work fine until it gets to the part where the Finder needs to select and duplicate a file. At that point it chokes. If anyone out there could point me to a solution, I’d be eternally grateful.
Thanx, mike


property blankPdfFileData : "%PDF-1.4
1 0 obj
<< /Type /Catalog
/Pages 3 0 R
>>
endobj
3 0 obj
<< /Type /Pages
/Kids [ 4 0 R]
/Count 1
>>
endobj
4 0 obj
<< /Type /Page
/Parent 3 0 R
/MediaBox [ 0 0 612 792]
/Contents 5 0 R
/Resources << /ProcSet 6 0 R >>
>>
endobj
5 0 obj
<< /Length 35 >>
stream
…Page-marking operators…
endstream
endobj
6 0 obj
[/PDF]
endobj
xref
0 7
0000000000 65535 f
0000000009 00000 n
0000000074 00000 n
0000000120 00000 n
0000000179 00000 n
0000000300 00000 n
0000000384 00000 n
trailer
<< /Size 7
/Root 1 0 R
>>
startxref
408
%%EOF
"

property destinationFolder : ""

on run
	set pdfToSplit to choose file with prompt "Choose a PDF file to split" of type {"PDF "}
	set destinationFolder to choose folder with prompt "Choose a folder for the split PDF files."
	processFile(pdfToSplit)
end run

on open openedItems
	set destinationFolder to choose folder with prompt "Choose a folder for the split PDF files."
	repeat with i from 1 to the count of openedItems
		set currentItem to item i of openedItems
		set the itemInfo to info for currentItem
		if (folder of the itemInfo is false) and ¬
			(alias of the itemInfo is false) and ¬
			(the file type of the itemInfo is "PDF ") then
			
			processFile(currentItem)
		end if
	end repeat
	tell application (path to frontmost application as text)
		display dialog "Finished splitting the PDF into multiple files." buttons "OK" default button "OK" giving up after 15
	end tell
end open

on processFile(pdfToSplit)
	tell application "Finder"
		set pdfFileName to name of pdfToSplit
		set blankPDFname to "zzBlank PDF" --.pdf
		set blankPDF to destinationFolder & blankPDFname as string
		set blankPDFwrite to open for access file blankPDF with write permission
		write blankPdfFileData to blankPDFwrite
		close access blankPDFwrite
		set file type of file blankPDF to "PDF "
		set creator type of file blankPDF to "CARO"
	end tell
	if (count of characters in pdfFileName) is greater than 20 then
		set newPdfFileName to characters 1 thru 20 of pdfFileName as string
	else
		set newPdfFileName to pdfFileName
		if newPdfFileName ends with ".pdf" or ".PDF" then
			set newPdfFileName to characters 1 thru -5 of newPdfFileName as string
		end if
	end if
	tell application "Acrobat 5.0"
		open pdfToSplit with invisible
		set pageCount to count of PDPage in document pdfFileName
		repeat with currentPage from 1 to pageCount
			set currentPage to addLeadingZeros(currentPage, 2) of me
			set currentPdfFilename to newPdfFileName & "-" & currentPage & ".pdf" as string
			set currentPdfDestination to destinationFolder & currentPdfFilename as string
			
			open file blankPDF with invisible
			insert pages document blankPDFname after 1 from document pdfFileName starting with currentPage number of pages 1
			delete pages document blankPDFname first 1 last 1
			save document blankPDFname to file currentPdfDestination
			close document blankPDFname
			tell application "Finder"
				
				
				select file blankPDFname of destinationFolder
				duplicate selection
				select file (blankPDFname & " " & "copy") of destinationFolder
				set x to selection as alias
				set name of x to currentPdfFilename
			end tell
		
		end repeat
		close document pdfFileName
	end tell
	try
		tell application "Finder"
			delete file blankPDF
		end tell
	end try
	tell application (path to frontmost application as text)
		display dialog "Finished splitting the PDF into multiple files." buttons "OK" default button "OK" giving up after 15
	end tell
	
end processFile

on addLeadingZeros(numberToFormat, maxLeadingZeros)
	set the thresholdNumber to (10 ^ maxLeadingZeros) as integer
	if numberToFormat is less than the thresholdNumber then
		set the leadingZeros to ""
		set the digitCount to the length of ((numberToFormat div 1) as string)
		set the characterCount to (maxLeadingZeros + 1) - digitCount
		repeat characterCount times
			set the leadingZeros to (the leadingZeros & "0") as string
		end repeat
		return (leadingZeros & (numberToFormat as text)) as string
	else
		return numberToFormat as text
	end if
end addLeadingZeros