10.5: Use Quick Look from the command line

Nov 16, '07 02:30:00PM

Contributed by: srhaber

For all you Leopard users out there, here's a handy tip on how to use Quick Look from the command line. Leopard ships with a command called qlmanage. The -p option shows a preview of the file passed to the command. In the terminal, type the following:

qlmanage -p thefile
As you'll see, it also generates a ton of text output when run. You can prevent this by creating the following shell script:
#!/bin/bash
qlmanage -p "$@" >& /dev/null &
The >& /dev/null prevents output from displaying, and the final & runs the process in the background so a new prompt displays in Terminal. Save this script as an executable file and store it somewhere in your PATH (I stored mine in a home bin folder used for custom-made scripts). I recommend naming it something short like ql.

When using the script, you can close the Quick Look window with the mouse (the conventional way), or close it in Terminal by getting the pid from the ps command and using kill pid#.

[robg adds: This hint originally appeared on the author's blog; check there for any udpates. I actually prefer the script without the last &, as you can then close the Quick Look window with a Control-C (but you cannot work on anything else in that same window until you do so, of course).]

Comments (6)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20071104012738617