Pass a File to Automator for excuting shell script

Get help. Get answers. Let others lend you a hand.

Moderator: Mr_Noodle

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?
Dellu
 
Posts: 17
Joined: Thu Dec 12, 2013 6:26 am

Hazel will automatically pass the file in to Automator. You have to make sure the first action in your Automator workflow accepts a file.
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

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?
Dellu
 
Posts: 17
Joined: Thu Dec 12, 2013 6:26 am

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.
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City


Return to Support