Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Using Quick Look from the Command Line UNIX
Sometimes you need to Quick Look a file, but you're in Terminal or iTerm or something. If you're dealing with images, you want to see them before you do anything. But you don't want to use the open command. That's where qlmanage comes in.

qlmanage is a CLI tool that, from the manpage, is a 'Quick Look Server debug and management tool.' It's got more options than described below, but those are for developers debugging QL.

The -p option generates a preview, as if you'd tapped the Space bar in the Finder. The -t option generates thumbnails, like in Coverflow or Info For. Here, then, are typical uses of the tool:
  • qlmanage -p '/Users/Name/Music/Player.mp3'
    Generates a QL window in Terminal.
  • qlmanage -t '/Users/Name/Pictures/Image.png'
    Generates a window with a thumbnail.
  • qlmanage -p '/Users/Name/Documents/Nurse.doc' '/Users/Name/Movies/Liters.mpg'
    Generates a QL window in Terminal with a page-through option to see both docs.

[crarko adds: I tested this, and it works as described. The Quick Look window that opens displays a [DEBUG] tag in the title bar along with the file name. As mentioned in the comments section, this previous hint shows this was also available in 10.5. ]
    •    
  • Currently 2.67 / 5
  You rated: 4 / 5 (27 votes cast)
 
[15,826 views]  

Using Quick Look from the Command Line | 14 comments | Create New Account
Click here to return to the 'Using Quick Look from the Command Line' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
No "space bar" goodness
Authored by: SeanAhern on Jul 13, '10 08:34:59AM

This does work well for making rapid Quick Look windows for data. The biggest problem, though, is that you can't use the space bar to make the Quick Look window go away like you can with "normal" Quick Look in the Finder.



[ Reply to This | # ]
Alternative keyboard exit
Authored by: lullabud on Jul 13, '10 09:26:21AM

Using the spacebar would be nice and consistent, but at least we have ctrl-c and cmd-. to get out.



[ Reply to This | # ]
No "space bar" goodness
Authored by: dmw on Jul 13, '10 04:17:49PM
I've been using the following script for this. You can close the window by hitting any key, including space.

#!/bin/sh
# This script originates from:
# http://www.unix.com/shell-programming-scripting/59605-trap-key-press-script.html#post302182133
qlmanage -p "$@" &
main=$!

tput smso
echo "Press any key to return \c"
tput rmso
oldstty=`stty -g`
stty -icanon -echo min 1 time 0
dd bs=1 count=1 >/dev/null 2>&1
stty "$oldstty"
echo

kill $main


[ Reply to This | # ]
No "space bar" goodness
Authored by: Vynce on Jul 18, '10 06:51:20PM
That seems like an incredibly complex way of waiting for a keypress. The following script is much simpler and works just as well in my testing. To be honest, I didn't actually test your version of the script. Does it provide some other benefit that I'm just not seeing?
#!/bin/sh

qlmanage -p "$@" &>/dev/null &
QL_PID=$!

echo "Press any key to return"
read -s -n 1

kill $QL_PID


[ Reply to This | # ]
No "space bar" goodness
Authored by: dmw on Jul 19, '10 07:39:08AM
Does it provide some other benefit that I'm just not seeing?
In this venue, you're right, it is overly complicated. Its one benefit over using read -n 1 is that it's technically more portable across UNIXs. On OS X, sh is really bash, which provides the -n option. The real sh doesn't have this option.

But since this is a Mac forum, and the script itself is Mac specific (using qlmanage), your method is preferable. And to be honest, I think it may be unlikely you'd find a modern UNIX variant where sh isn't really bash, so I think I'm going to retire this snippet in favor of yours. Thanks!

[ Reply to This | # ]
Using Quick Look from the Command Line
Authored by: rotaiv on Jul 13, '10 08:48:48AM

Great tip - I am a CL junkie so I will be using this for sure.

I looked at the man page but it does not list all the options. To see a full list of switches, just run qlmanage with no parameters and you'll get the full list.



[ Reply to This | # ]
Using Quick Look from the Command Line
Authored by: DougAdams on Jul 13, '10 09:19:09AM

FWIW: I recalled that this worked in Leopard, booted into 10.5, and it does. No [DEBUG] there, though. Also, if you pick a media file it plays automatically. Doesn't seem to be a flag to prevent this; didn't get auto-play in 10.6.

---
Doug's AppleScripts for iTunes
dougscripts.com



[ Reply to This | # ]
Using Quick Look from the Command Line
Authored by: DougAdams on Jul 15, '10 08:09:15AM
With regard to Leopard auto-playing media files that I mentioned above: for an AppleScript I just added a dummy item like so:
do shell script "qlmanage -p " & quoted form of POSIX path of aPath & " dummy >& /dev/null &"
In Leopard, this presents a QL window with previous and next arrows, and no auto-play. Of course, the "next" item is a blank display. Also, I've posted a script that will QL selected iTunes tracks. Works great with viewing PDFs from within iTunes--no Preview necessary! See Have a Quick Look.
---
Doug's AppleScripts for iTunes
dougscripts.com


[ Reply to This | # ]
Using Quick Look from the Command Line
Authored by: asmeurer on Jul 13, '10 10:32:00AM
Using Quick Look from the Command Line
Authored by: crarko on Jul 13, '10 11:28:55AM

Yeah, it is a dup. I may just leave this one because I think the examples are more understandable, and it applies to 10.6 as well now.

Thanks,

Craig A.



[ Reply to This | # ]
Using Quick Look from the Command Line
Authored by: arcticmac on Jul 13, '10 06:16:05PM

I'm a fan of the -o option to qlmanage, which causes it to output the native form that it actually displays. Usually, this is amounts to reducing to an image, a PDF, RTF, or HTML. For example, it can be useful as a way to take source code and get a syntax-highlighted version as RTF.

For example:
qlmanage -p -o /tmp myfile.cpp



[ Reply to This | # ]
Using Quick Look from the Command Line
Authored by: philostein on Jul 14, '10 09:26:52PM

Great tip, thanks! Can be used with Quicksilver's 'Run a Text Command in Terminal' to Quick-look files from anywhere.



[ Reply to This | # ]
Using Quick Look from the Command Line
Authored by: xth on Aug 06, '10 03:52:11AM

How would you do this? I can't get it to work. If I find an image, say, I can't get 'Run Text in Terminal'
I tried a few different ways but none worked



[ Reply to This | # ]
Using Quick Look from the Command Line
Authored by: philostein on Aug 31, '10 07:22:42AM

I meant you could get an image file path in Quicksilver, put it into a command in the text window and run that using 'Run a Text Command in Terminal', without opening Terminal first (not so sexy).

However, I wrote a Quicksilver action that does what you're expecting, it's a little kludgy but it does the job:
http://db.tt/G7i1m3s

Put it in -/Library/Application Support/Quicksilver/Actions and relaunch Quicksilver. Find some images (different parent folders are OK), hit tab and bring up the 'Quick Quick Look' action. Typing 'QQ' works for me. It'll show your images over whatever app you happen to be in. Close the Quick Look window to bring Quicksilver back with the files.

One advantage of the last part is you can right-arrow into the selection again and re-select the files you want to use/trash etc.

Cheers, philostein.



[ Reply to This | # ]