Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save zhaopengme/bd92e17463e5d83d3ca37bca19053da6 to your computer and use it in GitHub Desktop.
Save zhaopengme/bd92e17463e5d83d3ca37bca19053da6 to your computer and use it in GitHub Desktop.
Script to Export Keynote Presentation Files to PDF or JPEG
on sansExt(theFileName)
do shell script "file=" & theFileName & ";" & "echo ${file%.*}"
end sansExt
on getExt(theFileName)
do shell script "file=" & theFileName & ";" & "echo ${file##*.}"
end getExt
on run argv
set keynote_path to (item 1 of argv)
set out_path to (item 2 of argv)
set extension to getExt(out_path)
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
#!/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
osascript keynote_export.applescript "$keyfile" "$OUTFILE"
done
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment