Created
August 25, 2012 21:44
-
-
Save MattiSG/3471239 to your computer and use it in GitHub Desktop.
Extract PDF preview from Pages document
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
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