I recently had an interesting request to convert pdf, .sh, .py, .doc, .docx, rtf and .log files from an OS X Server into html so they could be viewed using the wiki. Mountain Lion server has WebDAV, but the files are spread throughout the system and need to be copied to a central location. Many of which have tags in them that when viewed via html end up getting parsed funny in a browser. It turns out that Apple has a command called textutil, which can convert data from all these formats except pdf (which doesn’t need to be converted ’cause it doesn’t jack files up when viewed in a browser). To use textutil to convert data, run the command followed by the -convert option (which is followed by the output type where output types include xt, rtf, rtfd, html, doc, docx, odt, wordml, or webarchive). In this example, we’ll just convert a shell script in ~ called conv.sh into an html file:
textutil -convert html ~/conv.sh
You should now have a file at ~/conv.html that can be viewed, so let’s open it:
So far so good. But we need to move some of these, so we’ll use the -output option. For example, let’s look at moving our .gitconfig file to /WebData and calling it gitconfig.html instead of .gitconfig:
textutil -convert html ~/.gitconfig -output /WebData/gitconfig.html
Next, we actually need to merge some files into one. We’ll use the -cat option followed by the output type for that, with all of the inputs at the end of the command, as follows (where parsedlogs1.doc parsedlogs2.html are merged into a new file called publishedlogs.html in the /WebData directory):
textutil -cat html -output /WebData/publishedlogs.html parsedlogs1.doc parsedlogs2.html
Using curl and other tools we can then access this data, although in most cases it will need to be pretty secure. Protect the target directory with a .htaccess (Realms are basically still an option via WebDAV in the Server app in Mountain Lion) and you will be able to access the output of this data via links in the Wiki service or simply as a shared directory using the WebDAV Wiki integration.