Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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