Getting XML Tidy (xmllint) to work on TextWrangler 4.0

TextWrangler has recently released a major update - version 4.0. A lot has changed, check out the release notes here.

One of the things that changed is the way it handles scripts and text filters. If you don't want to read through the whole thing, here's the main part:

There are two fundamental types of runnable file: "text filters", which accept the selection range (or entire document, if no selection) as input, and which return text that replaces the selection range (or document); and "scripts", which do neither. In unix-y terms, text filters accept the selection range on STDIN, and STDOUT replaces the selection range.

It just happens that I use XML Tidy a lot to format xml documents in a pretty way. To do that I had a nice little script (which is just a xmllint command really) for which I assigned a shortcut (alt+cmd+p). That made my workflow pretty fast. The problem is that this script stopped working as before so it took a while to find out why but I found a thread in google groups about this issue and someone from Barebones helped find the solution. So in summary, here's what you have to do to make XML Tidy work again in TextWrangler 4.0:

  • Paste this into a file
XMLLINT_INDENT=$'\t' xmllint --format --encode utf-8 -
  • Save with the name under ~/Library/Application Support/TextWrangler/Text Filters/
  • Open TextWrangler, write some unformatted xml, and try it out from Text menu > Apply Text Filter
  • To make it even easier, go to Preferences > Menus and Shortcuts and set a shortcut like I did (alt+cmd+p)

Hope that helps!

43 comments to Getting XML Tidy (xmllint) to work on TextWrangler 4.0

Leave a Reply




You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>