[OS X TeX] Can a TeXShop engine give the PDF name?

Michael Sharpe msharpe at ucsd.edu
Tue Dec 3 19:30:40 EST 2013


On Dec 3, 2013, at 3:51 PM, Chris Goedde <cgg.lists at gmail.com> wrote:

> On Dec 3, 2013, at 10:26 AM, Duncan Murdoch <murdoch.duncan at gmail.com> wrote:
> 
>> I'm writing a TeXShop engine for Sweave.  On a complicated project, it might be that the current file is Chapter.Rnw, but the engine will eventually run pdflatex on Book.tex, producing Book.pdf.  My engine can determine all of these names from the Chapter.Rnw file.
>> 
>> Is there a way for the engine to tell TeXShop that the PDF from the current typesetting operation is Book.pdf?
>> 
>> I have found that using Applescript to open Book.pdf is not quite right:  if the preview was already open from typesetting Book.tex, then I get a second copy.  (I don't get two copies from "open"ing it twice; there's something different about the way TeXShop opens it as a preview than opening it just as a file on its own.)
>> 
>> Thanks for any help.
> 
> I would love to be able to do the same thing reliably.
> 
> Here’s a piece of an engine I use to achieve something similar. The part below is the piece that tells TeXShop to open the correct pdf file. I’m not sure if it’s the same thing you tried via Applescript. My version doesn’t work very well in Mountain Lion or Mavericks; it worked great before that. (Actually, it can cause TeXShop to crash in Mavericks; I’ve reported this to Dick Koch.) Applescript is pretty finicky, though, so I thought I’d post it in case it gives you an idea for something that actually works.
> 
> It would be really cool (and useful to me) if TeXShop supported some way for engines to communicate the name of the pdf file back to TeXShop for viewing.
> 
> Chris
> 
> -----
> #!/bin/tcsh
> 
> osascript << EOF                                                                          
> tell application "TeXShop" 
> open posix file "$cwd/foo.pdf"
> activate
> set index of window "$1:foo.pdf" to 1
> tell document "$1:foo.pdf" to refreshpdf
> end tell                
> EOF                                                                                       
> -----

Though AppleScript can appear flaky, and does indeed change from one version of OSX to another, there is usually a workaround. One of the things that changed a couple of updates ago is that Open in the TeXShop dictionary now leads to error -1712, for reasons I can't explain. If you change your script to catch the error, it will work reliably. Eg,

#!/bin/tcsh

osascript << EOF                                                                          
tell application "TeXShop" 
	try
		open posix file "$cwd/foo.pdf"
		activate
		set index of window "$1:foo.pdf" to 1
		tell document "$1:foo.pdf" to refreshpdf
	on error
	end try
end tell                
EOF                                                                                       

Michael


More information about the MacOSX-TeX mailing list