Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm working on a program that generates an image. I can keep the image open in Preview and when the image changes, Preview refreshes it, but only when I alt-tab (sorry, command-tab) to it. I'd like to keep the image in view and have it auto-refresh without touching it. Is that possible?

(One ridiculous way I've found to do this is with a script that converts the image to a PDF file which I can keep open in Skim.app (a PDF reader) which has that ability.)

share|improve this question
    
A program does not have a feature you want it to have, and using another application to solve your problem is a "ridiculous way"? –  Daniel Beck Jan 12 '11 at 5:37
1  
The conversion to PDF is what makes it an ugly solution. If Skim.app could view images (like .png) it would be a great solution. –  dreeves Jan 12 '11 at 7:48

2 Answers 2

up vote 3 down vote accepted

Open AppleScript Editor and enter the following:

tell application "Preview" to activate
tell application "AppleScript Editor" to activate

Replace the second application's name with the program you want to have frontmost. Save as scpt and incorporate a call to this script into your program to refresh Preview:

osascript refresh-preview.scpt

You can alternatively use Automator to create a Service that receives no input with the Run AppleScript action and the above code. Save, and assign a keyboard shortcut in System Preferences. Not exactly automatic, but easier than getting the mouse to focus Preview.


Using the program open would be another idea, although using the switch -g (don't bring to foreground) opens the file in a new preview window every time its been modified, even if it's already open. All windows get updated though, without being brought to the foreground.

share|improve this answer
    
Oh! This is perfect! It looks like open -g image.png actually does exactly what I want. It doesn't seem to open a new preview window each time. Thanks so much for the help! –  dreeves Jan 12 '11 at 10:57
    
@dreeves Probably depends on the way your program handles changes to the file. I tried it with Automator and the rotate image action, and it behaved as I describe. –  Daniel Beck Jan 12 '11 at 11:05

You could use applescript to give Preview focus every x seconds.

share|improve this answer

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.