How do I combine these two shell commands into a Service? I run the following two commands on markdown files to get a nicely formatted PDF.

pandoc file.md -o file.html --css=markdown.css 
prince file.html file.pdf
rm file.html


How would I automate this? I'd like to right-click a markdown file, navigate to services, and choose convert markdown to PDF.

I know I should use Automator and I tried but couldn't link the right steps together. In my example above, file is the filename that needs to be the argument. I got as far as starting a new Automator service, choosing Files &amp; Folders, and Get Selected Finder Items and got stuck there.

Update: Pandoc = http://johnmacfarlane.net/pandoc/

Prince = http://www.princexml.com/

Update #2 for clarity

If I am in a folder with a markdown file named test.md,  then the complete command line syntax would be:

pandoc --from=markdown --to=html test.md --css=~path/to/css/markdown.css -o test.html


(Note: I have been able to automate this as a service and have named it Markdown to HTML)

Here is that code:

 for f in "$@"
 do 
/usr/local/bin/pandoc --from=markdown --to=html "$f" --css=/Users/fooo/Documents/Code/css/markdown.css -o "$f".html 
done


Now to convert that bit of html to PDF is something I am not able to link in. But the command line syntax for that would be:

prince test.html -o test.pdf
What about an Automator service like this one:


The payload is the shell script

 for f in "$@"
 do
    pandoc "$f" --css=markdown.css | prince - "$f".pdf
 done


Whatever the selected file or files, the service runs them through pandoc's Markdown parser, then takes the resulting html and processes it with prince, naming the output the original file name with a .pdf extension added.

The piping removes the need for you to manage temporary files.