File last modified on August 18, 2022


Generating an ePub

Bash Approach

There are several ways to generate an ePub. If the ePub file structure was followed and the name of the main folder is FooBar:

/ FooBar
/ file-structure contents

In on your Mac type cd and space and drag the folder FooBar to the Terminal window then press return. Terminal should look like this before return:

cd path/to/folder/FooBar

If this command worked it can be validated with the command pwd which shows the full path of the directory from Users and then the command ls -l should render:

drwxr-xr-x 3 USER 1804855622 96 Oct 8 09:55 META-INF
drwxr-xr-x 9 USER 1804855622 288 Oct 8 09:55 OEBPS
-rw-r--r-- 1 USER 1804855622 20 Oct 8 09:54 mimetype

If the above is accurate a one line command to generate the ePub can be achieved with:

zip -rX ../${PWD##*/}.epub mimetype META-INF/ OEBPS/

AppleScript Approach

If you're not interested to learn how to do this in the terminal feel free to download the app epub-zipper. does support drag and drop so in the above example you would drag FooBar on top of it and it will create FooBar.epub in the directory FooBar exists.

Decompress an ePub

Bash Approach

There might be a time when an ePub needs to be edited and if you're needing to modify the internals of an ePub for any reason you can do this in the Terminal with this bash script:


Download and save the file whatever you'd like (example:

Run the script in the Terminal: bash

It is strongly suggested to create a directory structure such as:

  • processing: directory where ePubs go to be manipulated.
  • shell: directory for all your scripts to be executed.
  • processing/output: directory for all ePubs to be moved to once you're done scripting against them.

The unzip script assumes these and there are fallbacks if these global variables are not set:

  • LOC: This is the location to point where the ePub exists. This should be set if the script is intended to be in it's own directory.
  • OUT: This location should be set if you want the finished script to put the files anywhere else other than where the file is being worked on.

If either global variables are left empty the script assumes that the script and ePub are in the same directory. If this isn't true the script will error out.

Last build: Thursday, 08/18/2022, 01:01:08 AM