Easy Text File Conversion on the Mac

Like a lot of other web developers, clients provide me content for their sites/applications in all sorts of formats, and it can get a little crazy. But it turns out that a little terminal utility on the Mac can help the stress of text file conversion.

The utility is called textutil and you can access it by going into your Applications > Utilities > Terminal, running Terminal, and then typing textutil. If you type the command without any arguments you’ll see a fairly strong list of options. Textutil supports conversion of txt, rtf, rtfd, html, doc, docx, odt, wordml, and webarchive formats.

Running textutil isn’t as hard as it looks. For example, I have a lot of clients that send me material in .docx or .odt format. I like to convert them over to .rtf files for quicker review (so Word or OpenOffice doesn’t have to load up). I make sure I’m in the same directory as the file I’m working with of course, and I execute:

textutil -convert rtf -output introduction.rtf introduction.docx

Once that’s done, you’ll notice an .rtf file is now in the same directory containing the original material.

Now the power of textutil doesn’t end there. Sometimes I want to convert a bunch of files and combine them into a single file. To do that I do something like:

textutil -cat rtf -output combined_project.rtf *.docx

Doing this takes all the .docx files in the current directory and combines them into a single .rtf file called combined_project.

If you have to deal with client provided text a lot, take a serious look at textutil – it has some great features hidden within it’s depths (like font resizing).