So I wanted to convert all my epubs to mobi files for my Kindle without having to use the graphical Calibre software. Turns out, contained within the application package for Calibre on my Mac, there's a brilliant little utility called ebook-convert.

The application

% cd /Applications/
% ./ebook-convert source.epub
% echo The Bird is The Word

Looking at the help files, it appears it supports many different formats, not just epub. It also determines what file type to export based on the extension you provide.

The application of the application

With this in mind, you could write any number of shell or awk scripts to convert a bunch of epub files to mobi based on any criteria you so wished.

Perl remains my favourite Swiss Army Chainsaw, so I wrote a script to convert each epub in the current folder, and is flexible enough that I can change it later. I'm a fan of clear reusability :)

#!/usr/bin/env perl -W
use strict;
use warnings;
my $parser = "/Applications/".
foreach my $mobi (<*.epub>) {
	$mobi =~ s/.epub/.mobi/;
	print("CONVERTING $mobi\n");
	system("$parser '$_' '$mobi'");