Page 1 of 1

Pandoc shell script

PostPosted: Tue Mar 13, 2012 9:07 pm
by mattm9
Hi, I'm trying to create a rule for a folder that will allow me to drop in a markdown file and have it converted to rtf using Pandoc.

I have this command working in terminal:

Code: Select all
pandoc -s -f markdown testing.md -o testing.rtf


but when I try using a shell script like:

Code: Select all
pandoc -s -f markdown "$1" -o "$1".rtf


I receive an error. I wondered whether anyone could provide a hint as to what I'm doing wrong?

Thank you.

Re: Pandoc shell script

PostPosted: Wed Mar 14, 2012 12:54 pm
by Mr_Noodle
How about testing it outside of Hazel using the exact same script as the one you are using in Hazel. Just give the script an argument when calling it.

Re: Pandoc shell script

PostPosted: Sun Apr 08, 2012 1:26 am
by TimeTraveler
I have exactly the same problem, although my script is slightly different:

Code: Select all
/usr/local/bin/pandoc -H ~/Altair/Desk/TeX/ms-ipad.tex --latex-engine=/usr/local/texlive/2011/bin/x86_64-darwin/xelatex "$1" -o "${1%mmd}"pdf


If I run the script on its own, it works perfectly. Within Hazel, as an "Embedded script," it gives me the following error message (from the Console):

Code: Select all
Shellscript exited with non-successful status code: 43

Re: Pandoc shell script

PostPosted: Mon Apr 09, 2012 11:18 am
by Mr_Noodle
It might be that the pandoc script is returning an error. If you run it in a shell, right afterwards, do:
Code: Select all
echo $?


That will output the status code. If it's non-zero then the script is returning an error code of some sort. In that case, I'd suggest checking the docs for pandoc. If there is no error, then the program is faulty in returning a non-zero code.

Re: Pandoc shell script

PostPosted: Tue Apr 10, 2012 1:21 am
by TimeTraveler
I followed the instructions and I get this:
Code: Select all
echo $?
0

What should I try next?

Re: Pandoc shell script

PostPosted: Tue Apr 10, 2012 11:36 am
by Mr_Noodle
Other things to try:

- Look up the error code. Maybe it'll shed some light on what's going on.
- Try it in an external script.

Also, keep in mind that you can't rely on any environment variables being set so if the script relies on any, that might cause problems.

Re: Pandoc shell script

PostPosted: Tue Apr 10, 2012 4:52 pm
by miklb
I'd love to see a solution for using pandoc with Hazel as well. I'm attempting to convert an HTML document (which was originally a .rtf file I converted with textutil) to Markdown.

Code: Select all
filename=$(basename "$1")
file=${filename%.*}
output_filename="$file.md"
pandoc -o $output_filename $1


Is what I tried, to no avail. If I use
Code: Select all
$ pandoc -o test_file.md test_file.html

from terminal, it works just fine

Re: Pandoc shell script

PostPosted: Wed Apr 11, 2012 1:54 pm
by Mr_Noodle
Poking around, I found this: http://support.markedapp.com/discussion ... processing

Not sure if this is the issue but try adding the following line to the beginning of the script:

Code: Select all
export HOME=/Users/username


Make sure to replace the path to your home directory for /Users/username.

Re: Pandoc shell script

PostPosted: Thu Apr 12, 2012 3:12 am
by TimeTraveler
I have tried both suggestions (of course, changing the user name):

Code: Select all
HOME=/Users/username

and
Code: Select all
export HOME=/Users/username


But I keep getting the same error.
Code: Select all
Shellscript exited with non-successful status code: 43


I have tried running the shell command as a script from Terminal, and it works flawlessly. So, my guess is that Hazel is forgetting to setup something before launching the shell script.

Any thoughts?

Re: Pandoc shell script

PostPosted: Thu Apr 12, 2012 11:43 am
by Mr_Noodle
Hazel does not set up anything because it's not an interactive shell. If you need certain environment variables set, you need to set them up or run your .profile or .bashrc or whatever of many files that may get executed in a shell. I also suggest contacting the author of pandoc to see what environment variables he expects to be in place. You might also want to ask him what the errors codes are.

Re: Pandoc shell script

PostPosted: Thu Apr 12, 2012 12:13 pm
by Mr_Noodle
Oh, and BTW, to execute a "startup" file in your script, do something like:

Code: Select all
. ~/.profile


Note there's a space after the first dot.

Re: Pandoc shell script

PostPosted: Fri Apr 20, 2012 5:14 pm
by TimeTraveler
I posted a question in the Pandoc forum, and John MacFarlane gave the the solution. It is necessary to setup the path in the shell script. To do it, you need to find out the path in Terminal, with the command:

Code: Select all
$ echo $PATH
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/usr/texbin:~/.scripts


Then you add the path in the script run by Hazel:

Code: Select all
export PATH=$PATH:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/usr/texbin:~/.scripts


Now Hazel works as expected.