print file if filename has specific characters in it

can anyone help me pls!!

im trying to create a workflow where i can automatically print a pdf file to a network printer, i would want the script to only print files that specifically contain the characters ‘_IMP.pdf’ at the end of the file.

the pdf files will be newly generated and would sit in various sub directories of an afp or smb mounted NAS drive on a mac OSX 10.6.8 machine.

any suggestions would be greatfully received. I am not a coder!!!

thanks all

Model: mac pro
Browser: Safari 536.30.1
Operating System: Mac OS X (10.6)

Hi Kevin,

The following script scan a path and search all folders.
For every folder get the list of files and if one file ends with “_IMP.pdf” print it using LPR.

property finalFoldersList : missing value
property numPDFPrinted : missing value

set folderPath to "Macintosh HD:Users:stefano:Desktop:Test:"
set finalFoldersList to {}
recursiveCheck(folderPath)
printPDF()
display dialog "Printed " & numPDFPrinted & " PDF files." buttons {"OK"} default button 1

on recursiveCheck(folderPathToCheck)
	tell application "Finder"
		set foldersList to (name of every folder of item folderPathToCheck)
	end tell
	set numFolder to count foldersList
	repeat with j from 1 to numFolder
		set newFolderPath to (folderPathToCheck & item j of foldersList & ":") as string
		copy newFolderPath to end of finalFoldersList
		recursiveCheck(newFolderPath)
	end repeat
end recursiveCheck

on printPDF()
	set numPDFPrinted to 0
	repeat with f from 1 to count finalFoldersList
		set folderPath to item f of finalFoldersList
		tell application "Finder"
			set filesList to name of every file in folder folderPath
		end tell
		repeat with d from 1 to count filesList
			set documentPath to (item d of filesList)
			if documentPath ends with "_IMP.pdf" then
				set numPDFPrinted to numPDFPrinted + 1
				set fullPathDocument to (folderPath & documentPath) as string
				do shell script "/usr/bin/lpr -P Xerox_7800 -o media=A4 -o fit-to-page " & quoted form of (POSIX path of fullPathDocument)
			end if
		end repeat
	end repeat
end printPDF

Stefano - Ame

Browser: Safari 537.75.14
Operating System: Mac OS X (10.8)