Last active
February 28, 2018 16:26
-
-
Save mgbckr/28679d827a306075ee2fd24b4a37dcf8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/bin/bash | |
# | |
# colorpages_printstring.bash | |
# | |
# Tool to print only color pages from a PDF (duplex). | |
# Generates a string to be used for common printing dialogs which only contains pages (back and front) with color. | |
# | |
# usage: colorpages_printstring <your>.pdf | |
# | |
# requirements: ghostscript (gs) | |
# | |
# TODO: Remove duplicates | |
pages=`gs -o - -sDEVICE=inkcov $1 |sed '/^Page*/N;s/\n//'|grep -v -e '0.00000 0.00000 0.00000' |grep Page|sed 's/Page \([0-9]*\).*/\1/g'` | |
ranges=() | |
for i in ${pages}; do | |
if (( $i % 2 )); then | |
ranges+=($i-$((i+1))) | |
else | |
ranges+=($((i-1))-$i) | |
fi | |
done | |
string=$(printf ",%s" "${ranges[@]}") | |
string=${string:1} | |
echo $string |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment