Connecting MacPerl to a PostScript printer

[email protected] (Alan Fry) Fri, 25 May 2001 11:06:32 +0100
Newsgroups perl.macperl.toolbox
Message-ID <p05010400b733d0699a7f@[158.152.146.73]>
A problem has arisen in a setup in which a laser printer is shared 
between Windows machines and an Apple. MacPerl applications on the 
Apple send their PS output to the printer.

The command:

	open(PRINTER, "+>Dev:Printer") or die "no printer";

works to an extent. If AppleTalk is off, then the 'open' 'dies'. 
However if the printer is switched off or (in this setup) switched 
over to the Windows machines, instead of 'die'ing the Mac hangs. A 
'force quit' to end the hang results in a mouse-freeze crash.

The problem can be avoided in a somewhat clunky way by following the 
'open' with a MacPerl::Choose(). If the printer is connected its name 
appears in the chooser list and the function returns the address. If 
the printer is off or otherwise disconnected the only option is to 
'cancel' in which case the function returns 'undef', which can be 
used to steer the program to a reasonably graceful exit.

The arrangement introduces a manual step into the program which it 
would be nice to avoid, but worse, in MacPerl 5.6.x there will be no 
MacPerl::Choose() so it won't be possible at all.

Another puzzle with the printer connection is that no returns are 
ever received:

	while (<PRINTER>) {
		s/\012/\015/g;
		print;
	}

prints nothing, even if, for instance, a PS error is deliberately 
sent to the printer. In this particular application it doesn't 
matter, but there are other situations where it might matter.

I wonder if it might be possible to devise a small module to improve 
the situation and provide for MacPerl facilities like Adobe's 
'PSTool'. Has anyone any thoughts on this or experience in this area?

Alan Fry