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/calibre.app/Contents/MacOS
% ./ebook-convert source.epub destination.mobi
% 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;

my $parser = "/Applications/calibre.app/".
    "Contents/MacOS/ebook-convert";

foreach (<*.epub>) {
    my $mobi = $_;
    $mobi =~ s/.epub/.mobi/;
    print("nCONVERTING $mobin");
    system("$parser '$_' '$mobi'");
}

print("nALL YOUR EPUB ARE BELONG TO MOBI! :Dn");