Batch converting a bunch of text files is no-one’s idea of fun.
Maybe someone’s sent you a tonne of documents that only open in a program you don’t have access to, or you need to share some Pages documents with a colleague who’s a die-hard Windows fan.
While you could work your way through these documents and change their formats one-by-one, you could also save yourself the time and effort, by converting them en masse with a single command.
In this article, I’ll show you how to quickly and easily convert any txt, html, rtf, rtfd, doc, docx, wordml, odt, or webarchive file, using your Mac’s built-in ‘textutil’ tool.
Convert a single file with textutil
While textutil is designed to take the pain out of mass file conversions, if you’re new to the command line then you may want to try converting a single file first.
You can only interact with textutil from the command line, so you’ll need to launch macOS’ Terminal:
- Open a new Finder window.
- Navigate to ‘Applications > Utilities.’
- Double-click ‘Terminal.’
To convert a single file, type the following command into the Terminal window:
textutil -convert (desired file format) (full file path)
For example, if you had an essay.txt file stored on your Desktop, and you wanted to convert this file to DOC format, then you’d use the following:
textutil -convert doc /Users/myusername/Desktop/essay.txt
Then, press the ‘Enter’ key on your keyboard, and textutil will create an essay.doc file on the Desktop, without deleting the original.
If at a later date you needed to convert this essay.doc file into a Rich Text File (RTF), then you’d run the following command:
textutil -convert rtf /Users/myusername/Desktop/essay.doc
Save yourself some typing!
There’s a huge range of Terminal commands at your disposal, but many of them require you to type the complete file path for one or more files. Depending on where a file is stored on your Mac, this can involve a significant amount of typing, and if you get a single letter wrong then the command isn’t going to work as expected.
You can save yourself some typing, by finding the file in question, and then dragging/dropping it into the Terminal window, which will automatically add the complete file path, file name and file extension to your command.
For example, if you wanted to use this trick with the previous command (textutil -convert rtf /Users/myusername/Desktop/essay.doc), you’d need to:
- Type textutil -convert rtf into the Terminal window.
- Open a Finder window, and navigate to the Desktop/essay.doc file.
- Drag and drop the essay.doc file into the Terminal window.
- Press the ‘Enter’ key on your keyboard, and the command will run as normal.
Convert multiple text documents with a single command
In reality, if you only needed to convert a single text file, it’d probably be quicker to change the format manually. The real power of textutil, lies in how easy it is to convert multiple files, with a single command.
The easiest way to convert a bunch of text files, is to place them all in the same folder, and then use the following command:
textutil -convert (desired file format) (folder path)/*.(current file type)
For example, if you had a folder named ‘notes’ stored in your ‘Documents’ folder, which was full of TXT files that you wanted to convert to RTF, you’d run the following command:
textutil -convert rtf /Users/yourusername/Documents/notes/*.txt
This will create duplicates of all your TXT files, in RTF format, in the same folder as the original files.