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

Force the Finder to show text file previews Desktop

This is one of those "it's so obvious I can't believe I've been using OS X for two years without figuring it out" hints.

It's always frustrated me that the Finder wouldn't show previews of XML, CSS, XSL, or any other text files without a ".txt" suffix. I always assumed there was a table someplace that mapped file extensions to a "preview as text" property, but I had no idea where the table was.

I still don't know whether that table exists or how to modify it, but I've found another method that works: simply set the Finder info type field to TEXT. A simple

  find . -name *.xml -exec SetFile -t TEXT {} ;
is all it takes for XML files (within the current directory tree) to be previewable, assuming the Developer Tools are installed (SetFile is included with the Dev Tools).

D'oh!

    •    
  • Currently 2.33 / 5
  You rated: 1 / 5 (3 votes cast)
 
[11,395 views]  

Force the Finder to show text file previews | 13 comments | Create New Account
Click here to return to the 'Force the Finder to show text file previews' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Force the Finder to show text file previews
Authored by: Paul Burney on May 12, '03 10:34:35AM
Good hint. Please note that the backslash before the ; has been deleted by the mysterious geek log slashinator. Also, the command shown requires /Developer/Tools to be in your path. You may have better luck with this:

find . -name '*.php' -exec /Developer/Tools/SetFile -t {} \;

[ Reply to This | # ]
Force the Finder to show text file previews
Authored by: Paul Burney on May 12, '03 10:36:04AM
Doh! Take two

find . -name '*.php' -exec /Developer/Tools/SetFile -t {} \;

[ Reply to This | # ]
please, explain command by command
Authored by: elmimmo on May 16, '03 04:30:16AM

While this terminal tricks are really appreciated, could you please explain word by word what you are telling the Terminal to do? That way one could understand what that really does and take more profit from them in the future.



[ Reply to This | # ]
Force the Finder to show text file previews
Authored by: SOX on May 12, '03 11:35:47AM

how is this different than using get-info and in the open-with dialog there's a setting to set the default on all files with that extension ?



[ Reply to This | # ]
Force the Finder to show text file previews
Authored by: aranor on May 12, '03 11:46:42AM

Because the Finder shows a text file preview for all files it thinks are text, which happen to be files with either a .txt extension or a TEXT filetype. The Always Open With command doesn't set either of those.



[ Reply to This | # ]
Force the Finder to show text file previews
Authored by: seika7 on May 12, '03 12:22:56PM

I believe the Always Open With command changes the creator code (the program used to open the file) and not the type code which we need to change for this hint.



[ Reply to This | # ]
Force the Finder to show text file previews
Authored by: klktrk on May 12, '03 12:30:40PM

Thanks for the hint. I should point out, though, that this only makes files already created give previews in the Finder. So you'd probably have to add this script to your /etc/weekly.local or /etc/daily.local to get any real benefit in the long run.

I'm going to hold out for a Finder setting.

Also, if you want to process all sorts of files at once you could do like so:
find ~/ -type f \( -name '*.xml' -o -name '*.html' -o '*.php' \) etc....



[ Reply to This | # ]
Force the Finder to show text file previews
Authored by: tim_bissell on May 13, '03 06:54:37AM

> Also, if you want to process all sorts of files at once you could do like so:

find ~/ -type f \( -name '*.xml' -o -name '*.html' -o '*.php' \) -exec /Developer/Tools/SetFile -t {} \;

One problem with this command is that the SetFile is executed once for each file matched; this can result in thousands of processes being created, run and stopped. Of course the Unix gods thought of this, so they wrote the wonderful 'xargs' command:

find ~ -type f \( -name '*.xml' -o -name '*.html' -o '*.php' | xargs SetFile -t

xargs works with commands which expect a list of (file)names at the end of their argument list. It reads a list of names from its standard input, and constructs a command (based on the arguments given to it) with a list of names read from standard input. When the command being built reaches the maximum size, it executes it, then if there are any more names on the input, it starts building a new command.
'man xargs' on the command line gives a clearer description of it.



[ Reply to This | # ]
xargs --thanks!
Authored by: das_2099 on May 13, '03 11:11:09AM

Awesome! I never lookd at xargs before...thanks for the rather concise , very usefull hint!



[ Reply to This | # ]
xargs --thanks!
Authored by: tim_bissell on May 14, '03 05:35:19AM

Cheers!

I forgot to add a couple of useful options; MacOS X files and directories tend to have spaces in them, so you should use:

find .... -print0 | xargs -0 ....

instead of

find ... | xargs ...

(note those are zeros, not capital 'O's)



[ Reply to This | # ]
Doesn't work for me -- BBEdit
Authored by: frankie1969 on May 12, '03 01:05:43PM

Is this hint really just saying "give your text files the TEXT classic type code?"

I'd already given 99% of my text files type TEXT (and creator R*ch), using the fabulous FileUtilsCM plugin. But for some reason most of the previews are blocked by BBEdit, and it just diplays a big icon instead.

Suppose I should ask this on one of the BareBones.com mailing lists...



[ Reply to This | # ]
Doesn't work for me -- BBEdit
Authored by: theRegent on May 20, '03 01:02:58AM

I'm seeing the same behavior; BBEdit files aren't always showing text previews, even though they've all got the same Type/Creator codes and are set to open in BBEdit.

I've yet to find an explanation, though.

---
It's a little more starry eyed than thin-lipped.
http://regency.newarcadia.com/



[ Reply to This | # ]
Force the Finder to show text file previews
Authored by: elmimmo on May 13, '03 04:04:40AM

Well, as weird as it may seem, I assign 'TEXT' type to EPS files so that they show a thumbnail preview (if they already have it embedded of course). Just a few EPS will ignore the embedded thumbnail preview and display its text contents

I do this because if they have the expected type, EPSF, they will not show the thumbnail preview.



[ Reply to This | # ]