Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

herewego

macrumors newbie
Original poster
Dec 14, 2009
1
0
I have an Applescript someone wrote for me some years back and I now need this very script to simply check that the .pdf file extension exists before continuing. Can you help?

Here's the code...

Code:
set strWatchedFldr to "Walters_File_Transfer:CGC_Prints:"
set strRootStorageFldr to "Walters_File_Transfer:CGC_Prints:Original PDF:"
--set strPrinergyIN to "Walters_File_Transfer:SHF_CGConly:MikesTests:"
set strPrinergyIN to "Walters_File_Transfer:SHF_CGConly:SHF_CGprint:"
set strOriginalPDF to "Walters_File_Transfer:CGC_Prints:Original PDF:" -- you'll need to correct this, couldn't tell for sure from your screen shot

repeat
	
	tell application "Finder"
		open folder strWatchedFldr
		update folder strWatchedFldr
		--set sort column of list view options of Finder window "CGC_Prints" to modification date column
		--set sort column of list view options of Finder window "CGC_Prints" to name column
		set current view of Finder window "CGC_Prints" to icon view
		set current view of Finder window "CGC_Prints" to list view
		set bounds of Finder window "CGC_Prints" to {6, 350, 333, 565}
		try
			set strPDFFileName to the name of file 1 of folder strWatchedFldr
			activate
			set blnContinue to true
			set strPDFName to strPDFFileName
			set strPDFFile to (strWatchedFldr & strPDFFileName)
			set strPDFName to (trim ".pdf" off strPDFName from back side) as text
			set strPDFName to (trim ".PDF" off strPDFName from back side) as text
		on error
			set blnContinue to false
		end try
		if blnContinue then
			if (character 1 in strPDFName is "1") then -- HERE'S WHERE IT CHECKS IF IT NEEDS TO ADD THE JOB CODE TO THE FILE NAME
				set strNewPDFName to ("82" & (characters 2 thru -1 in strPDFName) as text)
			else
				if (character 1 in strPDFName is "2") then -- HERE'S WHERE IT CHECKS IF IT NEEDS TO ADD THE JOB CODE TO THE FILE NAME
					set strNewPDFName to ("84" & (characters 2 thru -1 in strPDFName) as text)
				else
					strNewPDFName to (character 1 in strPDFName) as text
				end if
			end if
			
			tell application "Adobe Acrobat Pro"
				activate
				--delay 30
				set skip warnings to true
				open strPDFFile with invisible
				set relPageCount to the count of PDPage of document 1
				set intSegments to (relPageCount / 16)
				set intDecSegments to (relPageCount div 16) as integer
				if (intSegments > intDecSegments) then
					set intSegments to (intDecSegments + 1)
				end if
				close document 1 saving no
				if (relPageCount > 64) then
					set relSegmentCounter to 0
					
					repeat intSegments times
						
						set relSegmentCounter to (relSegmentCounter + 1)
						open strPDFFile --with invisible
						set intTemp to (relPageCount as integer)
						if ((relSegmentCounter = 1) and (intSegments > 1)) then
							delete pages document 1 first 17 last intTemp
							save document 1 to (strPrinergyIN & strNewPDFName & "_1_16.pdf") with linearize
						else if (relSegmentCounter = intSegments) then
							set inttempLast to ((relSegmentCounter - 1) * 16) as integer
							delete pages document 1 first 1 last inttempLast
							set strFirstPage to (((relSegmentCounter - 1) * 16) + 1) as integer
							save document 1 to (strPrinergyIN & (strNewPDFName & "_" & (strFirstPage as text) & "_" & relPageCount & ".pdf")) with linearize
						else
							delete pages document 1 first ((relSegmentCounter * 16) + 1) last intTemp
							delete pages document 1 first 1 last ((relSegmentCounter - 1) * 16)
							set strFirstPage to (((relSegmentCounter - 1) * 16) + 1) as integer
							save document 1 to (strPrinergyIN & (strNewPDFName & "_" & (strFirstPage as text) & "_" & (relSegmentCounter * 16 as text) & ".pdf")) with linearize
						end if
						close document 1 saving no
						
					end repeat
					
					tell application "Finder"
						try
							move (file strPDFFile) to folder strOriginalPDF
						end try
					end tell
				else
					tell application "Finder"
						try
							copy (file strPDFFile) to folder strOriginalPDF -- simplest way was just to make a copy, then manipulate the original and then route it
							try
								set the name of (file strPDFFile) to (strNewPDFName & "_1_" & (relPageCount as text) & ".pdf")
								update folder strWatchedFldr
								try
									copy (file (strWatchedFldr & (strNewPDFName & "_1_" & (relPageCount as text) & ".pdf"))) to folder strPrinergyIN
									delay 3
									try
										delete (file (strWatchedFldr & (strNewPDFName & "_1_" & (relPageCount as text) & ".pdf")))
									end try
								end try
							end try
						end try
					end tell
				end if
			end tell
		end if
	end tell
	delay 600 -- a number in seconds, this controls show often it refreshes the hotfolder
	
end repeat
 
Try something like this:

Code:
set ext to name extension of (info for strPDFFile)
if ext is "pdf" then
    <<<code that does something to the file here>>>
end if

In a "real" programming language you would probably check that the extension is not "pdf", and then have a continue statement to go to the next item in the loop. But since AppleScript is bizarre and clunky and doesn't include a continue statement (actually it does, but it terminates the loop entirely, which is not what you want), it's easier to just enclose all your file processing code in the if block.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.