Introduction
PowerPoint presentation files (*.pptx) allow you to add notes to each slide. However, PowerPoint for Mac does not have a built-in feature to bulk delete these notes. This article automates note deletion using a shell script.
Shell Script Explanation
This shell script (delete_note.sh) performs the following operations:
-
Creates a temporary directory and stores its path in the
TMP_DIRvariable. -
For each pptx file in the current directory, it performs the following:
- Copies the
.pptxfile to the temporary directory. - Extracts the
.pptxfile in the temporary directory. - For each
.xmlfile in the./ppt/notesSlides/directory, clears the content of<a:t>tags. - Re-archives the extracted files into a
.pptxfile. - Copies the generated
.pptxfile back to the original directory.
- Copies the
-
Deletes the temporary directory.
Shell Script
#!/bin/bash
set -eu
TMP_DIR="$(mktemp -d)"
trap 'rm -rf $TMP_DIR' EXIT
for PPTX_FILE in *.pptx; do
if [ -e "$PPTX_FILE" ]; then
echo "Processing $PPTX_FILE..."
cp "$PPTX_FILE" "$TMP_DIR"
pushd "$TMP_DIR"
unzip "$PPTX_FILE"
rm "$PPTX_FILE"
find "./ppt/notesSlides/"*.xml | xargs -I{} sed -i '' -e 's/<a:t>[^<]*<\/a:t>/<a:t><\/a:t>/g' "{}"
zip -0 -r "$PPTX_FILE" ./* # do not compress (-0)
popd
cp "$TMP_DIR/$PPTX_FILE" "$PPTX_FILE"
fi
done
Background: PPTX File Structure
A PPTX file is actually a collection of XML files. Specifically, it has the following structure:
_rels/: Directory containing XML files that define relationships.docProps/: Directory containing XML files that define document properties.pptxDirectory containing XML files that make up the presentation body.slides/: Directory containing XML files with information for each slide.slideMasters/: Directory containing XML files with slide master information.notesMasters/: Directory containing XML files with notes master information.notesSlides/: Directory containing XML files with notes information for each slide.theme/: Directory containing XML files with theme information.
_rels/: Directory containing XML files that define relationships.[Content_Types].xml: XML file that defines content types.
These XML files are compressed into a PPTX file. In other words, to edit a PPTX file, you need to extract it, modify the XML files, and re-compress it. Not knowing this structure can leave you stuck when managing PowerPoint for Mac.