My goal is to create an EPUB file via an AppleScript, and I'm starting with semi-manually generating an EPUB file. My issue is that the IDPF EPUB validator reports that my MIMETYPE file isn't isn't the first file in my EPUB package or that my MIMETYPE doesn't exist. My AppleScript is creating the EPUB folder structure and a MIMETYPE file:
set EPUBMIMETYPEfilepath to ((EPUBfolderPath & ":MIMETYPE") as string)
set referenceToEPUBMIMETYPEfile to a reference to file EPUBMIMETYPEfilepath
open for access referenceToEPUBMIMETYPEfile with write permission
write "application/epub+zip" to referenceToEPUBMIMETYPEfile
close access referenceToEPUBMIMETYPEfile
So, later on when I have a collection of folders and files resembling a standard EPUB structure, I'm using the command line to ZIP up the EPUB:
zip -X0 ../epubFilename.epub MIMETYPE
zip -rDX9 ../epubFilename.epub.epub META-INF -x "*.DS_Store"
zip -rDX9 ../epubFilename.epub.epub OPS -x "*.DS_Store"
Later on I can unzip my EPUB and actually see that there's indeed a MIMETYPE file within, however perhaps not the first file because the META-INF folder is sorted first?
Question: does anyone have any tips to create an EPUB via the command line on a Mac?
As you found out, the mimetype filename must be lowercase. Of the files required by the EPUB format, only the META-INF/ directory should have an uppercase name. By the way, you only need one """zip -rDX9" command. The -r will recursively include the subdirectories and files into the .epub.
There are three Terminal commands you need to use to build your EPUB:
- Load in the mimetype file:
zip -X "[book_title_goes_here].epub" mimetype
- Load in the META-INF directory and exclude any .DS_Store files:
zip -rg "[book_title_goes_here].epub" META-INF -x *.DS_Store
- Load in the EPUB directory (or whatever you've named the directory where all of your content lives), and exclude any .DS_Store files:
zip -rg "[book_title_goes_here].epub" EPUB -x *.DS_Store
Don't forget to run your book through epubcheck (you can download an AppleScript app from Google Code; just drag and drop the EPUB file onto the AS app: https://code.google.com/p/epub-applescripts/downloads/detail?name=ePubCheck_3.0b5.zip&can=2&q=).
来源:https://stackoverflow.com/questions/25924095/make-mimetype-file-the-first-file-in-an-epub-zip-file