Hazel + Marked
Hi Brett, I'd like for Hazel to monitor a folder of text files and, when they're edited, to use Marked to save them as PDF files and save them in the same (or a different) folder. Is there a simple way to script this? I've been running in circles and could use some help.
Comments are currently closed for this discussion. You can start a new one.
Keyboard shortcuts
Generic
? | Show this help |
---|---|
ESC | Blurs the current field |
Comment Form
r | Focus the comment reply box |
---|---|
^ + ↩ | Submit the comment |
You can use Command ⌘
instead of Control ^
on Mac
Support Staff 1 Posted by Brett on 29 Aug, 2012 09:35 PM
There isn't right now. It's planned for the future, but the best bet right now is to use the multimarkdown CLI (or whatever variant you like) and the wkhtmltopdf CLI. If you get those installed, you'd tell Hazel to:
You can specify a CSS file in the headers of the document, and see
wkhtmltopdf -h
for more options for PDF output. You can also export an HTML file from Marked with embedded stylesheet and then cut the style out into a CSS file to include if you want Marked-style output. Both wkhtmltopdf and Marked use webkit, so the output is very similar.You can install both multimarkdown and wkhtmltopdf via Homebrew http://mxcl.github.com/homebrew/. If you prefer, you can also get decent output with pandoc, but wkhtmltopdf will probably be closer to what you're expecting.
Hope that helps.
2 Posted by Teddy Svoronos on 29 Aug, 2012 09:51 PM
Awesome, thanks Brett. Just so I'm clear, if my setup in Marked is rendering my TeX using Mathjax, will that be preserved by outputting this way?
For the record I just created a pretty crazy interface-driven Keyboard Maestro macro which seems to do the trick (I hope).
Support Staff 3 Posted by Brett on 29 Aug, 2012 09:55 PM
If you load the MathJax from the CDN in an "HTML Header:" metadata tag, I think wkhtmltopdf will process it.
xhtml header: <script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
Haven't tested, though, I'd be curious to know if that works.
I'm sure it got convoluted, but that's still awesome.
Support Staff 4 Posted by Brett on 29 Aug, 2012 10:05 PM
Just tried it out and it doesn't work with the homebrew version. It's possible, though, but tricky.
Search this page for "--javascript-delay" for ideas. You'd have to install the version from the Google Code site to get that working, I think. My copy doesn't seem to recognize that parameter or --redirect-delay.
Let me know if you happen to solve that one.
5 Posted by Teddy Svoronos on 30 Aug, 2012 03:20 AM
Thanks a whole lot for all this Brett. After a few hours I think I'm going to just stick with my Keyboard Maestro macro and have it try to launch every evening. Having my markdown notes PDFed once a day is ok for now, until I can do it in real time later!
6 Posted by Teddy Svoronos on 31 Aug, 2012 04:14 PM
Success! I think. I set up a Hazel script to monitor a folder for txt files & changes. If a file is changed (Date Last Matched is before Date Last Modified), it runs the following shell script:
export PATH=$PATH:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/texbin:/Users/tsvoronos/.rvm/bin
pandoc --self-contained --mathml "$1" -o "$1".html
wkpdf --source "$1".html --output "$1".pdf
(Where one should replace the second line with the result of "echo $PATH")
This then produces both an html file and a PDF file that incorporates image URLs and mathjax. Finally I have 2 other Hazel rules, one of which deletes the HTML file and the other moves the PDF to a "PDFs" subfolder of my Notes folder that's being monitored.
Hope this is useful, and any tweaks/thoughts would be appreciated.
7 Posted by Teddy Svoronos on 31 Aug, 2012 05:37 PM
Oops, I also append this to the end of all txt files using Mathjax
Brett closed this discussion on 05 Sep, 2012 06:14 PM.