Skip to content

Instantly share code, notes, and snippets.

@MattiSG
Created August 25, 2012 21:44
Show Gist options
  • Save MattiSG/3471239 to your computer and use it in GitHub Desktop.
Save MattiSG/3471239 to your computer and use it in GitHub Desktop.
Extract PDF preview from Pages document
extract() {
if echo $1 | egrep -q '.pages\/?$'
then arg="$1"
trimmed="$(echo $arg | sed 's:/$::' | sed 's:\.pages::')"
else arg="$1.pages"
trimmed="$1"
echo "source : $arg/QuickLook/Preview.pdf"
echo "dest : $trimmed.pdf"
fi
if cp "$arg/QuickLook/Preview.pdf" "$trimmed.pdf"
then echo "Extracted $trimmed"
if [[ $delete ]]
then delete "$arg"
fi
else echo "**Failed to extract $trimmed**"
fi
}
delete() {
rm -rf "$1"
echo "Deleted $1"
}
if [ $# -eq 0 ]
then echo "Usage: $0 [--delete] pages_doc_1 pages_doc_2 ..."
echo "--delete or -d : erase the original document if extraction was successful."
echo ".pages extension may be omitted"
exit
fi
if [ "$0" == "--delete" ] || [ "$0" == "-d" ]
then delete=0
fi
for file in "$@"
do
extract "$file"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment