Last active
November 17, 2018 21:03
-
-
Save knpwrs/4acd36c81534def91aa13f356e0c601f to your computer and use it in GitHub Desktop.
Export slide images from keynote and crop to a specific size.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -e | |
# $1 is the keynote file to process | |
FILE=$1 | |
OUTPUT_DIR=$(dirname $FILE)/output | |
FULL_DIR=$OUTPUT_DIR/full | |
CROP_DIR=$OUTPUT_DIR/crop | |
CROP_CMD="1920x650+0+215" | |
mkdir -p "$OUTPUT_DIR" "$FULL_DIR" "$CROP_DIR" | |
echo "Processing $FILE" | |
echo "Outputting to $OUTPUT_DIR" | |
# Export to images | |
osascript <<EOF | |
tell application "Keynote" | |
activate | |
set keynote_file to open ("$FILE" as POSIX file) | |
export keynote_file to ("$FULL_DIR" as POSIX file) as slide images with properties { image format: PNG, skipped slides: false } | |
close keynote_file saving no | |
end tell | |
EOF | |
# Crop images | |
for file in "$FULL_DIR"/*.png; do | |
/usr/local/bin/magick "$file[$CROP_CMD]" -gravity north -background black -extent 1920x1080 "$CROP_DIR/$(basename "$file" | sed 's|full|crop|g')" | |
done | |
# We're done! | |
osascript <<EOF | |
tell app "System Events" | |
display dialog "Done!" buttons {"Yay!"} | |
end tell | |
EOF | |
open $OUTPUT_DIR |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment