16

I have a workflow (LaTeX editing in Emacs) which produces PDFs that I then examine in Preview. Preview is smart enough to re-load the PDF when it changes, but it only does so when I click on the application and bring it to the foreground.

Is there a way to tell Preview to re-load the document (and stay in the background) using the command line?

Edit: To follow up, I'm perfectly happy to do a little AppleScript hacking or whatever (I've never used AppleScript, but it can't be too hard).

5

No simple solution that I can think of.

  • You can switch to using Skim, or another PDF previewer that supports the behavior you seek.
  • You can "open file.pdf" to refresh and bring Preview to the foreground, and then another command to bring your editor or terminal in front of it (open file.pdf; open -a Terminal.app).
  • Skim does what I want; thanks. It still likes to bring itself forward during the refresh, but I can work around that. Skim also affords much more effective AppleScripting than Preview (you can tell it to refresh directly). – Reid Nov 3 '10 at 21:51
5

If you want to use Applescript to bring Preview to the front, then all you need is this line:

tell application "Preview" to activate

You could also use the osascript command in the command line to run that script as well. There are specific things to look out for (escaping quotes and handling multiple lines). Examples on its exact use abound and it has its own man page.

  • Thanks; that would be partway there certainly. Is it possible to tell Preview to refresh but not come to the front? How does one figure out what AppleScript hooks are available for an app (or is that a new question I should ask)? – Reid Nov 3 '10 at 1:32
  • 2
    @Reid not really but you could add to your script a command to return you to the App you had before (in this case your TeX editor), that ought to be enough to trigger the Preview’s refresh and will put you back in business. – Martin Marconcini Nov 3 '10 at 4:31
  • @Martin, thanks - I got that to working. The one remaining problem is that the window order is twiddled; I'd prefer for it to remain exactly the same. – Reid Nov 3 '10 at 21:50
  • That would require fiddling with the index of each document (document n), but typically that's a read-only property. – Philip Regan Nov 4 '10 at 10:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .