Last Updated: February 25, 2016
· honzacz

Growl notifications with TeXShop

TeXShop is my *TeX editor of choice, however, it lacks one important feature - Growl notifications triggered by file compilation success or failure.

The individual commands used for compilation are defined in the specific engines provided by TeXShop, which are in reality simple shell scripts. By editing a TeXShop "engine" (in this case XeLaTeX) such notification can be easily added without modifying the application itself.

The engines are located in ~/Library/TeXShop/Engines/. Since I mostly use XeLaTeX, I duplicated the XeLaTeX.engine file and edited it to contain several Growl notifications triggered using growlnotify CLI client.

The core of the new engine, named XeLaTeX-custom.engine, looks like this:

growlnotify -s -d $IDENT --image "$IMAGE_RUN" -m "${DATE}"$'\n'"${MSG_RUN}" $BANNER
xelatex -halt-on-error -file-line-error -synctex=1 "$1" 

if [[ $? -gt 0 ]]; then
  growlnotify -d $IDENT -s --image "$IMAGE_FAIL" -m ${DATE}"$'\n'"${MSG_FAIL}" $BANNER
  PAGES=`cat ${BASENAME}.log | grep "Output written" | grep -o -E "\([^\)]*\)"`
  growlnotify -d $IDENT -s --image "$IMAGE_OK" -m "${DATE}"$'\n'"${MSG_OK}"$'\n'"$PAGES" $BANNER

The whole file is available as a gist. The Growl notifications are displayed as sticky and since they share one ID, they get updated, so they do not take up more screen estate. To avoid "lock-up" XeLaTeX runs in "halt on error" mode, which means that the compilation is aborted after an error is detected. The specific error message is then available in the console.

The custom engine can be triggered manually from the TeXShop typeset menu, or it can be selected by using the directive %!TEX TS-program = xelatex-custom at the beginning of a root file.


Say Thanks