Hello,

I am a long-time perl user, but am new to perl on OS X.

I have written a very simple script that reads printer commands from a text file and cats them out to a USB/serial port in order to print barcodes on a old-school printer we have. I am trying to make it easy for the people who will be doing all the printing (fairly novice mac users) so they only have to double-click the file containing the printing commands to have my script open it and print it. But I can't figure out how to do it...

I associated my printer files (*.zfdb files) with my perl script, and when you double-click them, the script indeed runs -- but it fails to find the file I double clicked and dies. I expexted to see the file name to be opened in @ARGV, but the only thing I got was the psn (process serial number).

For an example of a correctly working app, if I run the following command:

% open -a Emacs ~/Desktop/label-5-192.zfdb

emacs opens and my file is there to be edited.

If, however, I do this:

% open -a ZfishLabelPrinter ~/Desktop/label-5-192.zfdb

(where ZfishLabelPrinter is the installed name of my perl script) it can't find the file and it isn't passed in @ARGV.

Does anyone know what is happening here? Do I need to do something with apple events or somethine else?

My script is included below.

Any help is greatly appreciated,

julian


#!/usr/bin/perl


use strict;

print STDERR "$0\nCommand line arguments: @ARGV\n";

open INPUT, $ARGV[0] or die "Unable to open input: $!\n";
#open INPUT, "< /dev/stdin" or die "Unable to open stdin: $!\n";
#sysopen(INPUT, "/Users/catchen/Desktop/label-5-187.zfdb", 0);

# For testing
open OUTPUT, "> /dev/stdout";
# open OUTPUT, "> /home/catchen/label-test.txt";

# For Mac OS/X
#open OUTPUT, "> /dev/tty.USA19Hb1P1.1" or die "Unable to open output: $!\n";

while (<INPUT>) {
 print OUTPUT $_;
}

close INPUT;
close OUTPUT;

unlink($ARGV[0]) or die "Unable to unlink: $ARGV[0], $!\n";

Reply via email to