Monday, July 14, 2008

Truly Persistent QuickLook

I love the QuickLook feature in Apple's OS X Leopard (10.5.x). It's a great way to just see what's in a file without having to wait and first launch whichever app is associated with that particular file type. It's also great if someone sends you an Office document and you happen not to have Office (or iWork) on your machine. For instance, as long as there aren't lots of equations or important macros in a file, you can often view the contents of the document better with QuickLook than in, say, TextEdit, for Word files. And if it's an Excel or PowerPoint file, QuickLook may be your only option.

But there's one limitation of QuickLook that's been driving me crazy. As soon as you switch away from Finder (to another application), which is to say, as soon as Finder loses focus, the QuickLook window disappears. What I wanted was truly persistent QuickLook. There are a couple of hits on Google if you enter "persistent QuickLook" - but they only tell you to use Cmd+Y.... And that suffers from the same limitation as using the space bar to invoke QuickLook — at least, as near as I can tell.

Practically, this means that you can't view the Word (or Excel or Powerpoint) document while you type text into another program. Which is irritating, and, as far as I was concerned, rendered QuickLook very nearly useless — or at least, pretty much broken. I wanted QuickLook on the left, and TextEdit (or OmniOutliner or Pages, etc.) on the right, so I could transcribe the one to the other. I found myself frequently PDF'ing the source file so I could actually keep it up for reference while I worked.

Fortunately, there is a way to make the QuickLook window not disappear on you. You can invoke QuickLook from the command line, using qlmanage (man qlmanage for details). Irritatingly (though perhaps arguably correct behavior), qlmanage doesn't exit until the QuickLook window it summons has been closed — but we can get around that with a little dancing and a call to nohup. Here's how I do it:
nohup qlmanage -p "/path/to/file" > /dev/null 2>&1 &

This will bring up a QuickLook preview of the specified file, return you your prompt immediately, and suppress all of the output typically generated by nohup (both the "Appending output to nohup.out" message and the actual output that is typically appended).

Of course, you don't really want to have to open Terminal and type in that string every time you want a persistent QuickLook of a file. Neither do I. Automator comes to the rescue, and gives you the rest of the solution.

In Automator, make a new Workflow for which "Get Selected Finder Items" is the first step and "Run Shell Script" the second. In "Run Shell Script", change "Pass Input" from "as stdin" to "as arguments." Then, delete the template text Automator helpfully provides you with in the "Run Shell Script" box and replace it with:
nohup qlmanage -p "$@" > /dev/null 2>&1 &

Then select "Save As Plug-in..." from the File menu. Automator, again helpfully, offers to build you a Plug-in for Finder — which is exactly what you want. Name it something descriptive (I called mine "Persistent QuickLook" and click Save.

Now, open a Finder window, right-click on something, select "More..."->"Automator"->"Persistent QuickLook" (or whatever you named it), wait a couple of seconds, and — voilĂ ! you have a QuickLook preview of whatever you clicked that doesn't go away. That's a bit more work than merely hitting the space bar (and it takes a bit of time to open, which is a pity), but at least the QuickLook window won't disappear when Finder loses focus.

2 comments:

Bryan said...

Excellent tip thank you. Seems Snow 10.6 requires this to be a service now but still works. Now I'm just trying to figure out how to make the persistent quick look window stay open but not on top of all other windows.

Anonymous said...

thanks for the interesting information