How to Batch Convert DOCX Files to TXT Format with textutil in OS X
The Mac includes a fantastic command line tool called textutil which allows for quick text file format conversions, translating almost any text or word document type into another. We’ve discussed textutil for a variety of uses, but typically it has been for one-off conversions of a specific file into a new file type. This time around we’ll focus on batch converting a group of files that are in the common Microsoft Office “DOCX” format, which is basically a compressed XML version of a classic Office DOC file, into a simple TXT or RTF file format, which has greater compatibility.
Because textutil is a command line tool, users should be somewhat comfortable using the terminal before diving in, this is reflected in the first examples shown for those who know the command line well enough. If you’re new, though we will try to make it easy enough that almost anyone at any skill level with OS X should be able to follow along.
Batch Converting DOCX to TXT / RTF with textutil
For those who are adept at using the command line, the syntax necessary for batch docx to txt or rtf file conversion is as follows:
Convert DOCX to TXT:
textutil -convert txt /path/to/DOCX/files/*.docx
Convert .docx to .rtf :
textutil -convert rtf /path/to/docx/files/*.docx
The “-convert txt” or “-convert rtf” flag tells textutil to convert the files into the given format, and the rest of the command string is simply a path to the files in question. Then, a wildcard * is used with the .docx file extension to tell textutil to convert everything in that specified directory.
The freshly converted rtf or txt files will appear in the same directory as the original .docx files, the original dock files will not be overwritten or modified. That’s it, you’re all done. Obviously the txt file format is more universally readable than rtf, but RTF files maintain some formatting better than txt. Use whichever is necessary, or depending on the complexity of the docx files in question.
Batch Converting DOCX to TXT for Mac Terminal Newbies
If the above was over your head, don’t worry, you can make the process a bit easier by using a combination of the Finder and the Terminal, thanks to the print full path trick:
- Navigate in the Finder file system to the directory where the docx files are located which need to be converted, or drag the docx containing folder to the desktop
- Open the Terminal application, found in /Applications/Utilities/
- Type the following command syntax, adding a space at the end of ‘txt’, but don’t hit return yet:
- Go back to the Finder, now drag & drop the docx containing folder into the terminal window to print out the full directory path into the terminal
- Add at the end of the directory path “*.docx” without the quotes, the resulting command string at the terminal prompt should look something like this:
- Hit return to complete the batch conversion
textutil -convert txt
textutil -convert txt ~/Desktop/MyDocxFiles/*.docx
The new .txt files will appear almost instantly in the same folder as the original .docx files, they even have the same file name with the exception of the new file format extension. If you can’t tell the old file from the new files apart, be sure you have file format extensions set to visible in the Mac Finder to easily show the difference.
Thanks to James Harvard for the tip idea.