File last modified on August 18, 2022

Packaging

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:

txt
1
/ FooBar
2
/ file-structure contents

In Terminal.app 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:

bash
1
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:

bash
1
drwxr-xr-x 3 USER 1804855622 96 Oct 8 09:55 META-INF
2
drwxr-xr-x 9 USER 1804855622 288 Oct 8 09:55 OEBPS
3
-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:

bash
1
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. epub-zipper.app 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:

Gist:

Download and save the file whatever you'd like (example: unzip-pub.sh).

Run the script in the Terminal: bash unzip-pub.sh

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