Cups virtual printer / scripting

Hey folks:

I’m searching for someone with intermediate or advanced knowledge level working with cups printer daemon.

Scenario:

My goal is to let cups or some kinda virtual printer running on cups decide whether use my color ink printer or my grayscale laser printer.

I thought about achieving this, by either getting some information from the client (like document or photo setting for the virtual printer) or by letting a script go over the document and decide if it is necessary to use a color printer or grayscale.

greetings:

CodingSheep

Isnt grayscale still technically color because it uses all the color inks equally but with varrying density of dots?

Very easy to do.

Create your virtual printer, and when it comes time to select the driver, either say you have a sysV interface script and upload the following, or leave it at RAW (no driver) and drop the following script into /etc/cups/interfaces/ with the exact name of the printer, then restart cups.

#!/bin/bash 

REQID="$1"
USER="$2"
TITLE="$(echo "$3"|awk -F'/' '{print $NF}')"
COPIES="$4"
OPTIONS="$5"
ORIGIN="$(echo "$OPTIONS"|awk -F'job-originating-host-name=' '{print $2}' | awk '{print $1}')"
TIME="$(echo "$OPTIONS"|awk -F'time-at-creation=' '{print $2}' | awk '{print $1}')"

shift;shift;shift;shift;shift

your-color-test-program $*
RET=$?
if [ "$RET" == "0" ]; then
  lp -d colorinkjet -n "$COPIES" -o ColorMode=Color $*
else
  lp -d bwlaserjet -n "$COPIES" -o ColorMode=Monochrome $*
fi
1 Like