10.5: Add Quick Look support for certain file formats

Nov 08, '07 07:30:00AM

Contributed by: moondark

I have a lot of files that contains data in plain text format with different extensions -- things like .cfg, .dat and .tex. However, those files are not recognized by the Quick Look viewer. It is possible to make these other files visible with the default Quick Look viewers by simply adding a UTI (Uniform Type Identifiers) file reference to an application's Info.plist file.

For example, TeXShop is an application that writes Latex files in plain-text with the .tex extension. If you want to see these .tex files with Quick Look, conrol-click on TexShop.app in the Finder and chose Show Package Contents from the pop-up menu. Navigate into Contents, then open Info.plist with TextEdit and add the public.plain-text string to the UTTypeConformsTo key as follows:

First look for the UTExportedTypeDeclarations section in the original file:

...
  <key>UTExportedTypeDeclarations</key>
  <array>
    <dict>
      <key>UTTypeConformsTo</key>
      <array>
        <string>public.text</string>
      </array>
      <key>UTTypeDescription</key>
      <string>TeX text file</string>
      <key>UTTypeIdentifier</key>
      <string>org.tug.tex</string>
      <key>UTTypeTagSpecification</key>
      <dict>
        <key>com.apple.ostype</key>
        <string>TEXT</string>
        <key>public.filename-extension</key>
        <array>
          <string>tex</string>
          <string>latex</string>
          <string>ltx</string>
          <string>texi</string>
          <string>ctx</string>
        </array>
      </dict>
    </dict>
  </array>

Now add the public.plain-text string to the UTTypeConformsTo key:

...
  <key>UTExportedTypeDeclarations</key>
  <array>
    <dict>
      <key>UTTypeConformsTo</key>
      <array>
        <string>public.text</string>
        <string>public.plain-text</string>
      </array>
      <key>UTTypeDescription</key>
      <string>TeX text file</string>
      <key>UTTypeIdentifier</key>
      <string>org.tug.tex</string>
      etc...
To make the changes take effect, the UTI reference must be exported again. One way to do this is to try moving the application to another folder and then putting it back in its original location and opening it. However, it may be that a logout is required. Now you should see .tex, .latex, .itx, .texi and .ctx as plain-text in Quick Look. This trick can be extended to other applications by adding the public.plain-text or public.movie (for files that QuickTime can open) string to the UTTypeConformsTo key.

If your file doesn't have a UTExportedTypeDeclarations, you can add it to the Info.plist inside an application or bundle by copying the above keys (from the complete first section of code, not the abbreviated second bit) and changing public.filename-extension strings with the extensions of your application. You may need to change org.tug.tex to any other name, as in org.perian.mkv (for matroska video files, for example). This works fine with Perian and mkv files, so you can preview then in Quick Look.

Comments (34)


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