Create your own EPUB ebook files using Automator

A handy new addition in Mac OS X Lion makes it a piece of cake to create your own EPUBs that can be viewed in iBooks on an iPhone or iPad, or on any other eBook reader. Using a simple Automator action, it’s possible to take text from anywhere, for example from a web page or a PDF file, and convert it into EPUB format that displays beautifully on whatever device you use to read ebooks.

To do this, we need to set up an Automator workflow that does the conversion for us. Once this is done, creating EPUB files will be as simple as selecting some text, right-clicking on it and choosing “Create ePub book with selected text.”

Start by opening Automator, which is located in the Applications folder. If you haven’t used Automator before, don’t worry, it’s just a really simple app that allows you to automate repetitive tasks by building “workflows” using building blocks called “actions.” The type of workflow we are going to build is called a Service, which means it will be accessible via the Services menu when right-clicking on selected text.

To create the workflow, drag the following two actions from the Library onto the workflow area on the right:

  • New Text File
  • Text to EPUB file

Change the settings to match the following screenshot. The main things to note are changing the file name to temp, ticking the Replace existing files checkbox, and ticking Show this action when the workflow runs on the Text to EPUB action.

EPUB Workflow

Choose Save from the File workflow and name it “Create ePub book with selected text.” To test it out, select some text (this article for example) and right-click on it. Under the Services menu, choose Create ePub book with selected text. The following dialog should appear, allowing you to specify the title, author, filename, and cover image for the book.

EPUB Action

Once saved, simply drag the EPUB file into iTunes to add it to your Library. When you next sync your iPhone or iPad, it will be copied across and will appear in the iBooks app on your device.

iBooks

Retain text formatting

If your text contains a lot of formatting like different text colours and bullet point lists, you can modify the workflow slightly to retain this in the EPUB. Simply change the Service receives selected drop-down menu to rich text, and do the same for the File Format drop-down menu in the New Text File action. When you are finished it should look something like this:

EPUB Rich Text Action

Multiple Chapters

The above method creates an ebook with only one chapter. If we want to divide up the ebook into separate chapters and include a table of contents, we have to do things slightly differently.

In your Automator workflow, replace the first action with a Sort Finder Items action. You will also need to change the Service receives selected drop-down menu to documents.

EPUB Multiple Chapters Action

Next, prepare your text by saving each chapter as a separate text file, all in the same folder. The names of the files determine the order, so make sure they start with something like “Ch1”, “Ch2”, “Ch3” etc.

EPUB Folder of Chapters

Finally, select all the files (Command-A), right-click on them, then choose your service from the menu.

Adding images, audio and video

One last cool feature is the ability to embed media such as images, audio and video in your EPUBs. Unfortunately there’s not a lot of flexibility in how you do this — you can either place one item at the start or end of each chapter, or group them all together in a chapter at the end called “Illustrations”.

To do this, simply click the Add… button on the dialog that appears when your service runs, and choose the files you want to embed. Note that videos need to be encoded in a format that is compatible with the iPhone — you can do this using the great tool HandBrake.

blog comments powered by Disqus