Fly, Penguin!

I blog so I don't forget.

Create ODT files using ZIP

1 minute read #snippet #solved

So I wanted to test something, for which I needed to create or modify an ODT file. Since ODT files are just ZIPs, I thought “open, edit, zip, done” would be sufficient.

It’s not:

  • you need to create the ODT file using a special procedure.
  • you may not include extra files into the ODT file (e.g. no “notes.txt” or sth)

The 2nd thing you have to take care of yourself, for the first I wrote a small Mac automator script, using bin/bash as shell:

SAVE_DIR="$PWD"

while read input_dir ; do
    [[ -d "$input_dir" ]] || continue

    cd "$input_dir"
    touch _odt_create_log.txt
    exec > _odt_create_log.txt
    exec 2>&1

    set -x
    ODT_FILE="../$(basename "$input_dir").odt"
    rm -f "$ODT_FILE"
    zip      "$ODT_FILE" -0 mimetype
    zip -ruo "$ODT_FILE"    .         -x mimetype _odt_create_log.txt
    cd "$SAVE_DIR"
    set +x
done