# Can a TeXShop engine set the #PDFPATH#?

I have written an engine to run Sweave (a preprocessor) from TeXShop. It works fine on simple projects.

For complicated projects (e.g. books), I might want to run the preprocessor on a chapter (e.g. Chapter.Rnw), then run latex on the main file (e.g. Book.tex), which will include the processed chapter text using \input{}. The previewer should then show me Book.pdf.

If I set the TEX root to Book.tex, then my engine is called with Book.tex, the preprocessor never sees Chapter.Rnw, and it doesn't work. My preprocessor can be told that Book.tex is the main latex file, and the Sweave engine can run pdflatex on that file, but I can't see a way to tell TeXShop that Book.pdf should be shown in the previewer.

I asked a similar question recently on the TeXWorks mailing list, and in that case I was able to install a post-typesetting hook that determined the output file by examining the console log after running. Is there anything similar in TeXShop, or is there a way for my engine to send a message to TeXShop to tell it which file to preview?

Sending a message to TeXShop can be done using Applescript. For example, from the command line, this will open the PDF /path/to/my.pdf:

osascript -e 'tell application "TeXShop" to open "path:to:my.pdf"'

Be careful about the quoting; in your shell, it might be different.

This will open a second copy if the file is already open as a preview, but will not open a second copy if one was already opened this way. Is there a way to designate this file as the preview for the current compile, so I don't get a second copy?