Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

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).

share|improve this question
add comment

2 Answers 2

up vote 4 down vote accepted

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).
share|improve this answer
    
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
add comment

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.

share|improve this answer
    
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. –  Martín 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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.