Only print/save second page

I am saving a pdf email attachment to a folder using a mail rule. I setup folder actions using automator so that the attachments are automatically printed, but I really don’t want to print the entire file. It’s usually only the second page of the pdf I want to print. Any advice?

that looks great! since i am doing this as a folder action, i’m a little confused how to set it up, since the filename depends on which file is dropped into the folder…i guess that filename is stored in a variable somewhere and i need to get it?
i see the option in automator for do shell script, but not sure how i execute your script and specify the filename of whatever’s dropped in there. does that make sense?

i see what you are saying. automator attaches a workflow as folder action, but alternatively you can attach your custom script.

btw, i did figure out how to do this in automator which was very simple. you just add a shellscript to your work flow and from the drop down menu chose to Pass input: as arguments. i’m guessing here the input arguments are the filenames, b/c then using the following little script works fine:

for f in "$@"
do
	lp -P 2 "$f"
done