(OLDER) <- More Stuff -> (NEWER) (NEWEST)
Printer Friendly Version



Improving Leopard's QuickLook

2007/12/10



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":


#!/bin/bash
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:

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

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.


;


Click here to add your comments





Thu Dec 13 12:27:38 2007: Subject: file names containing space   anonymous


Of course, you could add:



IFS='

'



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



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

gravatar
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: Subject:   krimb1

gravatar
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: Subject:   TonyLawrence

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



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

gravatar
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: Subject:   TonyLawrence

gravatar
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: Subject:   TonyLawrence

gravatar
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: Subject:   krimb1

gravatar
Oops, my mistake! ^^

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



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. We appreciate comments and article submissions.

Publishing your articles here

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.

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.


book graphic unix and linux troubleshooting guide

My Troubleshooting E-Book will show you how to solve tough problems on Linux and Unix systems!



 I sell and support
 Kerio Mail server




pavatar.jpg
More:
       - MacOSX
       - Leopard
       - Shell


Unix/Linux Consultants

Skills Tests

Guest Post Here











My Favorites

Change Congress