APLawrence.com -  Resources for Unix and Linux Systems, Bloggers and the self-employed

Improving Leopard's QuickLook

Leopard's new "Quicklook" is a nice tool, but for stubborn old command line types like me, it has some limitations: it won't show me plain text files unless they have the extension ".txt". It's possible that somewhere there's a preference you could add to Quicklook, but I haven't heard of it yet.

There is another way to make Quicklook show "unknown" files: you can mess with the files Info.plist as explained at this MacOSXhints.com 10.5: Add Quick Look support for certain file formats post. But that's really only useful once you realize you WANT to look at the file; I wanted something more automatic.

A simple command line script does the job for me. I call it "looky":

qlmanage -p -c public.plain-text "$@" 2> /dev/null &

(I modified that from a MacOSXhints.com post.)

Not much to it, is there? All it does is force Quicklook to interpret the file as plain text. We could make it fancier if we wanted by checking to see if we need to add the "-c public.plain-text", but for my command line use, this is fine - I don't need anything smarter.

But perhaps you do, so here's the "smart" version:

# "smart" Quicklook script by http://aplawrence,com
if [ "$1" = "-f" ]
   qlmanage -p -c public.plain-text "$@" 2> /dev/null &
   exit 0
for file in "$@"
   if [ "${file##*.}" = "$file" ]
      qlmanage -p -c public.plain-text   "$file" 2> /dev/null &
      qlmanage -p   "$file" 2> /dev/null &

That let's us add a "-f" if we absolutely want to force the issue. but otherwise uses "ordinary" Quicklook for files with extensions, and forces them to be interpreted as text if there is no extension.

Put this in ~/bin, chmod 755 it, and at a Terminal prompt, use "looky filenames or wildcards" to see it in action.

By the way, on my own system I would not have bothered with all the extraneous quotes around "$file" - the only reason those are there is because of files with spaces in their names, and I would never create such a thing on my machine.

(OLDER)    <- More Stuff -> (NEWER)    (NEWEST)   

Printer Friendly Version

-> -> Improving Apple's QuickLook


More Articles by

Find me on Google+

Click here to add your comments
- no registration needed!

Thu Dec 13 12:27:38 2007: 3324   anonymous

Of course, you could add:



to deal with the problems about files containg spaces in their names.

Thu Dec 13 12:54:13 2007: 3325   TonyLawrence

Yes, I guess you could - though to my mind, spaces just do not belong in file names period.. :-)

Wed May 13 16:44:16 2009: 6359   krimb1

Just found your nice script for QuickLook-ing plain text files! Maybe I missed something, but is there someway to QuickLook these files without launching it from terminal with the "looky" command?

Wed May 13 16:51:14 2009: 6360   TonyLawrence

Yes, see the MacOSXhints.com reference in the second paragraph.

Wed May 13 17:05:45 2009: 6361   krimb1

Haha, wow sorry to overlook that!

Maybe I'm asking too much, but is there any way to modify the AppleScript to work with LaunchBar rather than Quicksilver? LaunchBar to me is much cleaner and zippy and I don't have any intention of going back to Quicksilver anytime soon.. Thanks in advance!

Wed May 13 17:08:28 2009: 6362   TonyLawrence

You may not be asking too much, but you are asking the wrong person - I know NOTHING about Launchbar.

Wed May 13 17:11:17 2009: 6363   TonyLawrence

And by the way: it's NOT Applescript and it's NOT Quicksilver :-)

Not that it matters for your question; just to forestall someone elses confusion.

Wed May 13 18:15:28 2009: 6364   krimb1

Oops, my mistake! ^^

Thu Mar 4 04:50:46 2010: 8174   anonymous


This is silly. If I have to go to Terminal, I'm gonna use less(1). less can search and more. Now, if there was some non-lame way to QuickLook at a script without a filename extension from the Finder, I'd be buying.

Thu Mar 4 12:31:38 2010: 8175   TonyLawrence


You can turn this into something you can use from the Finder, but I think you are missing the point entirely :-)

Of course you'd use "less" to look at text files. This is for when you want to use Quicklook to show a handful of things that *includes* text files that Quicklook ignores.

Wed Mar 24 20:54:13 2010: 8264   Michael


This was something I always wished the quicklook alias I had made would do, but I never thought to actually change it! Thanks for posting.

Mon Dec 20 13:00:01 2010: 9171   Smokey


First there was the problem of opening all non-extension'd files by default with TextMate. Then came the problem of opening all normal plain-text files with the fantastic TextMate for QuickLook plugin. I was stumped for quite a while, but now I present: HOW TO OPEN ALL FILES WITHOUT EXTENSION IN QUICKLOOK! This method allows you to choose whatever generator you wante, and does NOT rely on any scripting, or command line tools (for the quicklooking). Press space and you are good to go with a beautifully rendered preview.

I use this generator cuz it's the shit!

Without further ado:
1. Open a terminal and type "mdls <filename>" if you are targeting a specific file. Otherwise, go to step 2. Read the key "kMDItemContentType" and remember the value.
2. Edit /Library/QuickLook/TMQuicklook.qlgenerator/Contents/Info.plist
3. Under the key "LSItemContentTypes" there are some UTIs. Start duplicating lines and adding all the plaintext UTIs you can think of. Add AT LEAST public.source-code, public.source, public.plist, public.data, and public.plain-text. If you find something later that isn't rendering, come back here and add it.
4. Open terminal, press "qlmanage -r" then "qlmanage -r cache"

THAT'S IT! As crazy as this sounds, I couldn't find the info on how to do this even to this day. All I found was a crappy other generator, but I like Ciaran's because it uses my TextMate theme to render it.

I hope someone finds this useful!

Mon Dec 20 13:26:55 2010: 9173   Smokey


Sorry, I forgot to post the link to my favorite quicklook generator:

(it's the second one)

We salute you Ciaran. Thanks for all your amazing work!

Mon Dec 20 13:36:28 2010: 9174   TonyLawrence


Thanks. I hardly ever use any of this, and had pretty much forgotten about it!

Mon Dec 20 13:49:45 2010: 9175   Smokey


Haha, I know, I know. Every post I can find on the topic is 2-3 years old. It's like everyone gave up at the same time. :)

I just started using TextMate religiously 6 months ago, and recently reached the point as a programmer where it's a runaway reaction, and the more I learn the more I can do so the more I learn. So this was one of the things that irked the crap out of me, similarly to the keybinding situation. I couldn't find the info online anywhere I looked, so I figured I'll give it here where maybe it will pop onto someone's search results someday.

Don't miss responses! Subscribe to Comments by RSS or by Email

Click here to add your comments

If you want a picture to show with your comment, go get a Gravatar
Kerio Samepage

Have you tried Searching this site?

Unix/Linux/Mac OS X support by phone, email or on-site: Support Rates

This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more.

Contact us

Jump to Comments

Many of the products and books I review are things I purchased for my own use. Some were given to me specifically for the purpose of reviewing them. I resell or can earn commissions from the sale of some of these items. Links within these pages may be affiliate links that pay me for referring you to them. That's mostly insignificant amounts of money; whenever it is not I have made my relationship plain. I also may own stock in companies mentioned here. If you have any question, please do feel free to contact me.

I am a Kerio reseller. Articles here related to Kerio products reflect my honest opinion, but I do have an obvious interest in selling those products also.

Specific links that take you to pages that allow you to purchase the item I reviewed are very likely to pay me a commission. Many of the books I review were given to me by the publishers specifically for the purpose of writing a review. These gifts and referral fees do not affect my opinions; I often give bad reviews anyway.

We use Google third-party advertising companies to serve ads when you visit our website. These companies may use information (not including your name, address, email address, or telephone number) about your visits to this and other websites in order to provide advertisements about goods and services of interest to you. If you would like more information about this practice and to know your choices about not having this information used by these companies, click here.

This post tagged:

       - MacOSX

       - Scripting

       - Shell