Leopard QuickLook and HTML Files

WARNING: This post contains Super Geek Stuff.  Not for the faint of heart.

QuickLook is perhaps my favorite feature of Mac OS X Leopard.  Today, I found myself in need of viewing HTML files in QuickLook.  Unfortunately, I did not want to view the HTML file as rendered in a web browser (Webkit)–I wanted to see the raw code.

I already have the fantastic QLColorCode QuickLook Plug-in, so why not make HTML files display in QuickLook using that plug-in?

I started digging into QuickLook’s command line management interface “qlmanage” and initially, it seemed possible.  You can force a particular generator to render the file using the -g switch and providing the path to the generator you want to use.  Unfortunately, if that generator is not set up to render that ContentTypeUTI, it will ignore you.

Fortunately, it is easy to hack the qlgenerator to do what I needed.  Here is what I did:

  • Choose “Show Package Contents” for QLColorCode.qlgenerator (located in /Library/QuickLook or ~/Library/QuickLook)
  • Under the Contents folder, you should find the Info.plist file.
  • Make a backup copy of it!
  • Now, open Info.plist using Property List Editor.
  • Open Root -> CFBundleDocumentTypes -> 0 -> LSItemContentTypes and add a New Child.  The value should be public.html (the ContentTypeUTI for HTML documents)
  • Save Info.plist
  • From Terminal issue the command “qlmanage -r”

That’s it!  You should now be able to QuickLook your HTML files and see the code.  If you want to put it back the way it was, just remove your Info.plist, replace it with the backup you made above and reload your QuickLook daemon.

Bookmark the permalink.

One Comment

  1. Funny and cool site. Sorry to hear you’re a Mac addict. I loved the post on Cats. It was good. I’ll try to continue to visit. Thanks!

Comments are closed