Created
February 1, 2014 20:13
-
-
Save epochblue/8758063 to your computer and use it in GitHub Desktop.
A command line utility for automatically generating PNG thumbnails and CMYK prints for http://framemyrun.com/
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 | |
# A command line utility for automatically generating PNG thumbnails and | |
# CMYK prints for http://framemyrun.com/ | |
# | |
# Author: Bill Israel <[email protected]> | |
# | |
# LICENSE: | |
# This code is considered to be in the Public Domain. Use, copy, modify, | |
# distribute, sell, and do anything else you want with it. The author | |
# reserves no rights to this code. | |
# This script only runs on OS X | |
[ $(uname) != "Darwin" ] && echo "This script only runs on OS X." && exit 1 | |
usage() { | |
echo "usage: $(basename $APP) COMMAND DIRECTORY" | |
echo | |
echo "COMMANDS:" | |
echo " png Convert all PDFs in the given driectory into PNGs." | |
echo " cmyk Convert all PDFs in the given driectory into CMYK color space." | |
echo | |
echo "OPTIONS:" | |
echo " -h, --help Print this message" | |
echo | |
} | |
__get_filename() { | |
full=$(echo $1 | cut -f1 -d '.') | |
echo $(basename $full) | |
} | |
__get_directory() { | |
eval DIR=$1 | |
echo $(echo $DIR | sed 's/\/$//') | |
} | |
cmyk() { | |
[ -z $DIR ] && usage && exit 1 | |
[ ! -d $CMYK_DIR ] && mkdir $CMYK_DIR | |
for file in `ls $DIR/*.pdf`; do | |
filename=$(__get_filename $file) | |
sips --matchTo "/System/Library/ColorSync/Profiles/Generic CMYK Profile.icc" "$file" --out "$CMYK_DIR/$filename-cmyk.pdf" | |
done | |
} | |
png() { | |
[ -z $DIR ] && usage && exit 1 | |
[ ! -d $PNG_DIR ] && mkdir $PNG_DIR | |
for file in `ls $DIR/*.pdf`; do | |
filename=$(__get_filename $file) | |
sips -s format png "$file" --out "$PNG_DIR/$filename.png" | |
done | |
} | |
APP=$0 | |
CMD=$1 | |
DIR=$(__get_directory $2) | |
PNG_DIR="$HOME/Desktop/png" | |
CMYK_DIR="$HOME/Desktop/cmyk" | |
case "$CMD" in | |
cmyk) | |
cmyk $DIR | |
;; | |
png) | |
png $DIR | |
;; | |
-h|--help) | |
usage | |
exit | |
;; | |
*) | |
echo "ERROR: Unknown command or option: $CMD" | |
exit 1 | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment