|
Regarding the watermark generation process, although the bash script works, I immediately reach for my old friend (GNU) make(1) for that kind of task. Here's the Makefile: all: watermark
done:=$(wildcard *-BD.pdf)
src:=$(filter-out $(done),$(wildcard *.pdf))
marked:=$(patsubst %.pdf,%-BD.pdf,$(src))
watermark: $(marked)
%-BD.pdf: %.pdf
./watermark_script.sh $< $@
The done+filter-out mumbo jumbo is there just because without it, -BD.pdf would be matched by .pdf, and therefore would generate -BD-BD.pdf... and so on (this is a loophole that the original bash script has, if parallel runs are timed correctly). Putting the output files in another directory is left ans an exercise for the reader.The inotify script becomes: inotifywait -e create /home/user/pdfs && make -C /home/user/pdfs
There is another loophole here, in that the -BD.pdf are created in that directory, so the script gets run again. It doesn't matter for our makefile, which will do nothing on the second run, but there is the 'parallel runs if timed correctly' issue of the original bash script.Generally, GNU make has a bunch of very interesting facilities, making it much, much more powerful than its ancestors (BTW, people interested may want to take a look at an implementation of non-recursive make[0], which — while being awesome — also shows up some useful make tricks). Now, regarding the filesystem events and userland tools (which are awesome), I wish there was a unified front-end for this kind of things (inotify on Linux, fsevents on OSX...) PS: I wish the comment form supported something like markdown, so that I could escape those wildcards, and more. [0] http://stackoverflow.com/questions/559216/what-is-your-exper... |