#!/bin/bash

##### user variables 
##### check ghostscript docs for your printer type#######
printer_type=DJ8xx

#####resolution can be in 300x300,600x600,etc. format,
#####but a single number is enough
resolution=300

#### this is the photo quality, etc. stick to '1' for most purposes. 
print_mode=1

################ end of user variables ################################

# let's make sure to kill and 'restart' the daemon

for process in `ps -C spd -o pid=`;
	do 
		if ( test $process ) && ( test $process != $$ );
			then kill $process;
		fi;	
	done;

# set up an infinite loop

while true;
do {
	sleep 1; #this keep the queue from choking on its entries and trying to send garbage characters
	for print_job in `ls -1tr /tmp/print* 2>/dev/null`;
	do {
		if test -a $print_job; # only if a ready to print file exists!!
		then {
			gs -sDEVICE=`echo $printer_type` -r`echo $resolution` -dPrintMode=`echo $print_mode` -dNOPAUSE -dBATCH -dSAFER -q -sOutputFile="/dev/lp0" $print_job ;
			rm $print_job; # cleanup the files so as not to waste space
			};
		fi;
		};
	done;
	};
done;


