Skip to main content

A tool for manipulating Apple Keynote presentation files.

Project description

keynote-parser

build:

keynote-parser is a Python module for unpacking and re-packing Apple Keynote .key files. It supports Keynote files generated by Keynote version 8.3 (current as of January 2019).

Keynote uses a proprietary, compressed binary format to store its presentations. This format is comprised of a zip file containing images and videos, as well as Snappy-compressed Protobuf .iwa files containing metadata, text, and all other definitions used in the presentation.

keynote-parser unpacks these component files into .yaml files in a directory, making them editable by text editors and/or scripts, then allows re-packing of these files into a working Keynote archive.

What could you use this for? Well, I use it to allow versioning of Keynote files in Git, which makes diffs more understandable (rather than binary), as well as modifying text in Keynote files in response to external scripts. (e.g.: figures that update from databases before giving a presentation)

Installation

pip install keynote-parser

Usage

# Unpack MyPresentation.key into ./MyPresentation/
keynote-parser unpack MyPresentation.key

# Re-pack ./MyPresentation/ into MyPresentation.out.key
keynote-parser pack ./MyPresentation/

# List the files within a Keynote archive
keynote-parser ls MyPresentation.key

# Dump a particular .iwa file into its yaml representation on stdout
keynote-parser cat MyPresentation.key /Index/Slide-00001.iwa

# Replace text within a Keynote file in-place
keynote-parser replace MyPresentation.key --find "hello world" --replace "hello dolly"

Formats

keynote-parser supports reading a list of replacements from a JSON file passed in as --replacements. This file must have the form:

{
  "replacements": [
    {
      "find": "regexp to search for",
      "replace": "string to replace with"
    },
    ...
  ]
}

This argument can be passed to keynote-parser replace to replace text in a Keynote file in-place. It can also be passed to keynote-parser pack to pack a directory into a Keynote file, replacing text along the way.

Replacing Images

The replacements json format can also be used to replace images in a Keynote file. To do so:

  • Use the keynote-parser ls command to determine the name of the image to replace.
  • Set the find pattern to the image's name, with the -\d\d\d suffix removed.
  • Set the replace field to the local path to the replacement image.

keynote-parser will automatically rescale the replacement image to fit all of the sizes of the target image.

Updates

As keynote-parser includes private Protobuf definitions extracted from a copy of Keynote, new versions of Keynote will inevitably create .key files that cannot be read by keynote-parser. As new versions of Keynote are released, the following steps must be undertaken:

  • Run proto-dump on the new copy of Keynote to dump new Proto files.
    • Any . characters in the Protobuf definitions must be changed to _ characters manually.
  • Connect to a running copy of Keynote with lldb (or any other debugger) and manually copy the results of [TSPRegistry sharedRegistry] into mapping.py.

Credits

keynote-parser was built by Peter Sobot but heavily based on prior work by Sean Patrick O'Brien. A copy of O'Brien's format documentation is included in the docs folder for posterity.

License

All code in this repository is licensed under the MIT License, save for protobuf_patch.py, which contains its own license.

Copyright 2019 Peter Sobot

Permission is hereby granted, free of charge, to any person obtaining a copy of this software
and associated documentation files (the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge, publish, distribute,
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or
substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

keynote-parser-1.0.8.tar.gz (766.2 kB view details)

Uploaded Source

Built Distribution

keynote_parser-1.0.8-py2-none-any.whl (417.4 kB view details)

Uploaded Python 2

File details

Details for the file keynote-parser-1.0.8.tar.gz.

File metadata

  • Download URL: keynote-parser-1.0.8.tar.gz
  • Upload date:
  • Size: 766.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.14.0 CPython/3.7.2

File hashes

Hashes for keynote-parser-1.0.8.tar.gz
Algorithm Hash digest
SHA256 2cea243b3d814fec915dd7423cbadaebdb51aa3c33aa514c3c2cdeb6b193d745
MD5 c6776e19098b7afe7839de5684ba6d1a
BLAKE2b-256 547e3bf47673f2ac04aee22425a3bfab4871bd7dc59cfd4210aeb270c211e064

See more details on using hashes here.

File details

Details for the file keynote_parser-1.0.8-py2-none-any.whl.

File metadata

  • Download URL: keynote_parser-1.0.8-py2-none-any.whl
  • Upload date:
  • Size: 417.4 kB
  • Tags: Python 2
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.14.0 CPython/3.7.2

File hashes

Hashes for keynote_parser-1.0.8-py2-none-any.whl
Algorithm Hash digest
SHA256 9aa7d769d2ef917797e134309c9f5f673aea96b8344725ba002cb8dafb8f8791
MD5 1d7b32be0173ecb0872e16f5edf48070
BLAKE2b-256 bc650fccef145a5f3be62105aeb69b4933dd5aa5f0ff1b38e29d6ecb9a444ee7

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page