Forked from kenjisato/keynote_export.applescript
Last active
October 18, 2022 14:01
-
-
Save stianl/f285d6163bcea7bb988058cc99816b06 to your computer and use it in GitHub Desktop.
Script to Export Keynote Presentation Files to PDF or JPEG
This file contains 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
on sansExt(theFileName) | |
do shell script "file=" & theFileName & ";" & "echo ${file%.*}" | |
end sansExt | |
on run argv | |
set keynote_path to (item 1 of argv) | |
set out_path to (item 2 of argv) | |
set extension to (item 3 of argv) | |
set basename to sansExt(out_path) | |
tell application "Keynote" | |
set keynote_file to open (keynote_path as POSIX file) | |
if extension is equal to "pdf" then | |
export keynote_file to (out_path as POSIX file) as PDF | |
else if extension is equal to "jpeg" then | |
export keynote_file to (basename as POSIX file) as slide images with properties { compression factor: 1.0, image format: JPEG } | |
else | |
do shell script "echo Output format " & extension & " not supported." | |
end | |
close keynote_file saving no | |
end tell | |
end run |
This file contains 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 | |
PACKAGE=$(basename $0) | |
VERSION="0.0.0.9001" | |
absolute_path () { | |
if [[ "$1" = /* ]]; then | |
echo ${1%/} | |
else | |
echo $(pwd)/${1%/} | |
fi | |
} | |
echo_help () { | |
echo "$PACKAGE - Export Keynote file to PDF/JPEG" | |
echo " " | |
echo "$PACKAGE [options] keynote_dir" | |
echo "options:" | |
echo "-h, --help show brief help" | |
echo "-o, --output-dir=DIR Output directory." | |
echo "-t, --type pdf or jpeg" | |
} | |
while test $# -gt 0; do | |
case "$1" in | |
-h|--help) | |
echo_help | |
exit 0;; | |
-o|--output-dir*) | |
shift | |
OUTPUTDIR=$(absolute_path $1) | |
shift;; | |
-t|--type*) | |
shift | |
TYPE=$1 | |
shift;; | |
*) | |
if [[ ! -z "$1" ]] && [[ ! "$1" =~ ^-+ ]]; then | |
param+=( "$1" ) | |
fi | |
shift;; | |
esac | |
done | |
INPUTDIR=$(absolute_path ${param[0]}) | |
if [[ -z "$INPUTDIR" ]]; then | |
echo "Input directory is not specified." | |
exit 1 | |
fi | |
[[ -z "$OUTPUTDIR" ]] && OUTPUTDIR="$INPUTDIR" | |
[[ -z "$TYPE" ]] && TYPE="pdf" | |
# The main loop | |
# Call an applescript to do the conversion. | |
for keyfile in $INPUTDIR/*.key; do | |
BASE=$(basename "$keyfile") | |
OUTFILE=$OUTPUTDIR/${BASE%.*}.$TYPE | |
EXT=${OUTFILE##*.} | |
osascript keynote_export.applescript "$keyfile" "$OUTFILE" "$EXT" | |
done | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment