Page 1 of 1

Pass a File to Automator for excuting shell script

PostPosted: Thu Dec 12, 2013 6:39 am
by Dellu
I have a few books in PDF format, and they are growing everyday as I am downloading more from internet. I want to split the books in 20 pages range and import the splitted pages into Devonthink. I have a shell script to split the PDF files. I know Hazel can run shell scripts. But, don't want that. I want the script to be executed inside the Automator. The reason is: to create complete workflow for importing into Devonthink using the Automator actions. How can Hazel pass my files to Automator so that the automator will execute the shell script on them and import them into DT?
Do I need a special command, or "$1" supposed to work for a script in the automator?
Her is the script if you want to look at:

Code: Select all
echo "Page count: "
ournum=`gs -q -dNODISPLAY -c "("$1") (r) file runpdfbegin pdfpagecount = quit" 2>/dev/null`
declare -i counter;
declare -i counterplus;
counter=1;
while [ $counter -le $ournum ] ; do
echo $counter
newname=`echo $1 | sed -e s/\.pdf//g`
reallynewname=$newname-$counter.pdf
counterplus=$counter+20;
# make the individual pdf page
yes | gs -dBATCH -sOutputFile=$reallynewname -dFirstPage=$counter -dLastPage=$counterplus -sDEVICE=pdfwrite "$1" >& /dev/null
counter=$counterplus
done;


I am completely novice; I get the script from other people. Can sb help me please?

Re: Pass a File to Automator for excuting shell script

PostPosted: Thu Dec 12, 2013 1:47 pm
by Mr_Noodle
Hazel will automatically pass the file in to Automator. You have to make sure the first action in your Automator workflow accepts a file.

Re: Pass a File to Automator for excuting shell script

PostPosted: Fri Dec 13, 2013 2:06 am
by Dellu
Mr_Noodle wrote:Hazel will automatically pass the file in to Automator. You have to make sure the first action in your Automator workflow accepts a file.


Thank you Mr_Noodles for the reply. Can you be a little bit more specific. Shall I keep "$1" inside the shell script of the automator?

Re: Pass a File to Automator for excuting shell script

PostPosted: Fri Dec 13, 2013 1:29 pm
by Mr_Noodle
That's more of a function of Automator itself and isn't really a Hazel thing. Looking at it (I assume you are using the "Run Shell Script" action), you want to set the "Pass input" pop-up to "as arguments". When you do that, it inserts a template script to process them. Hazel will only pass in one file/argument so the loop will only execute once.