: I managed to get perl to send faxes using the 'fax' front-end program, but
: never satisfactorily. I had to use root user to send faxes and I never managed
: to send any faxes that has graphics in the. In the end I installed PageSender,
: which has examples of sending faxes via AppleScript, and I called the
: AppleScript from perl. I know that sounds a lot more round-about but it had a
: lot of advantages for me.
Also, anything that supports AppleScript can be driven directly from Perl
using Mac::Glue.

Signature
"...while the Japanese are unable to duplicate the American film [market] they
can destroy it by this video cassette recorder." - Jack Valenti, 1982
I was intrigued by the original question and have done some
experiments on this G4 running Mac OS X 10.4.4.
Firstly I set the machine up so as to be able to send faxes from
applications using the Mac OS Print->PDF->Fax PDF… built in facility.
I have a broadband connection (ethernet modem) so it was necessary to
add a serial modem to dial up the remote fax machine's number. A USB
modem left over from the old internet dial-up days seemed promising.
There is on http://www.apple.com/support/ a very clear concise
document "Mac OS X 10.4: Adding a Bluetooth fax device". Although a
USB modem is not quite the same animal as a Bluetooth modem, the
recipe for the one works for the other. There is no point rehearsing
the 12 steps set out in that document here: anyone interested should
download the Apple document.
Having done this, Print->PDF->Fax PDF was found to work perfectly
with a number of applications, for instance BBEdit. This established
that the machine was capable of sending faxes. However it does not
settle the question of how to send faxes from within a Perl script.
If the document's application is scriptable a fax might be sent by an
AS to work the 'Print' facility, and that AS could be dispatched from
Perl. But that is by no means a good general solution to the problem.
However 'efax' does offer a more general solution. There are, I
think, various ways to call Unix from Perl. I have tended to write a
shell script for the Unix function, calling that from the Perl script
by 'tell application "Terminal" -- do script() -- end tell'. So the
first step was to get 'efax' working from the terminal.
By default 'efax' expects to find '/dev/cu.modem', which on this
machine does not exist. However 'ls /dev/' revealed (amongst a heap
of stuff) an entry 'cu.usbmodem08141'. Using this in place of the
default results in a command line:
efax -d /dev/cu.modem08141 -t [remote fax number] file.tif
That worked fine. (I am lucky that my ISP, demon, provides me with a
fax number for incoming faxes which it then e-mails to me, which I
can send faxes to myself for test purposes. Otherwise, I suppose, you
would need a local good friend with a fax machine in order to do the
experiments…)
The question then arose how to obtain a faxable version of the
document in question. This is most complex part of the problem simply
because of the huge number of possible document formats. In my own
small world I restrict the range to Postscript and PDF documents.
Postscript is useful because firstly one can very easily output '.ps'
files from Perl (for instance the perl script 'pod2ps' does this) and
secondly within Mac OS X every application can save its document as a
PDF file. Hence, On the whole, I need only deal with '.ps' and '.pdf'
files.
The question then arises as to how to convert these formats to G3
compressed '.tiff' files required by 'efax'. Now there is a companion
to 'efax' by the name of 'efix' which can do this but I must confess
so far I have been unable to make it work. However it appears that it
is effectively a front end for ghostscript, and therefore it seems to
me more sensible to use 'gs' directly. Even if one opts to use 'efix'
ghostscript must be installed. The mantra for converting a file to a
faxable format is:
gs -dSAFER -dBATCH -dNOPAUSE -sDEVICE=tiffg3 -dTextAlphabits=4 -
dGraphicsAlphaBits=4 -sOutputFile=outfile infile
Obviously one has complete freedom of choice about the outfile name
and extension, but 'gs' determines the infile format from the infile
extension I believe. By this means '.ps', '.pdf', '.txt' and a whole
heap of graphics formats can be converted to fax format. Again, from
Perl a shell script can be invoked by a AppleScript call to the
Terminal.
As Bill Stephenson says below there is a front end for both 'efax'
and 'efix' going under the name 'fax'. The command 'fax make file'
will produce a fax format file with the same name as file with .001, .
002 etc. appended. It uses 'efix', which in turn uses 'gs'. I can see
no advantage in this. Indeed there are snags with 'fax': for instance
it expects a US letter page size and truncates an A4 postscript page.
There appears to be no way of controlling page size. Similarly the
commmand 'fax send file' fails because it uses 'efax' with all
default settings, including the default serial modem. There appears
to be no way of overriding the 'efax' defaults from 'fax'.
I have not tried (yet) the suggestion of piping a file to 'lpr' --
certainly the serial modem appears in 'lpinfo' -- so it might well
work. However I think everything you might want to do from within
Perl can be done quite simply by firstly using 'gs' to convert the
file to faxable format and sending the fax by 'efax'. In both cases a
suitable shell script can be invoked from within a perl script by an
AppleScript 'do script' command.
I hope this may be of interest to some with my apologies to those
>not< interested in faxing from Perl for his long spiel.
Alan Fry
> I managed to get perl to send faxes using the 'fax' front-end
> program, but never satisfactorily. I had to use root user to send
[quoted text clipped - 31 lines]
>>
>> A laudable aim.
Bill Stephenson - 23 Jan 2006 17:34 GMT
> I was intrigued by the original question and have done some
> experiments on this G4 running Mac OS X 10.4.4.
>
> <snip>
Wow, thanks for sharing what you've learned! Admittedly, I haven't had
much time to play with this since I asked that question but your reply
puts me way ahead of where I was then. I'd also like to thank everyone
else that replied. If I get my "Fax the House" script finished I'll
post a copy of it.
Kindest Regards,
--
Bill Stephenson
Alan Fry - 24 Jan 2006 10:43 GMT
>> I was intrigued by the original question and have done some
>> experiments on this G4 running Mac OS X 10.4.4.
[quoted text clipped - 6 lines]
> thank everyone else that replied. If I get my "Fax the House"
> script finished I'll post a copy of it.
As a PS, <brian.mckee@gmail.com> suggested to me [slightly condensed]:-
>> Well, I'd skip the Perl -> applescript -> Terminal -> bash hoopla
>> why not just use system(efax command line) or just back-ticks.
Indeed that's much better, faster, and cleaner, and works fine.
Many thanks for your kind remarks. I look forward to seeing "Fax the
House" in due course.
Alan
Christian Huldt - 29 Jan 2006 16:14 GMT
24 jan 2006 kl. 11.43 skrev Alan Fry:
> As a PS, <brian.mckee@gmail.com> suggested to me [slightly
> condensed]:-
[quoted text clipped - 3 lines]
>
> Indeed that's much better, faster, and cleaner, and works fine.
how about using convert for producing the tiffs?
I think there is a version included in Mac OS X, but since I tend to
install imagemagick myself at some point I should not make any
promises...
John Delacour - 05 Feb 2006 20:17 GMT
After upgrading Perl to 5.8.8 including the new CPAN, I am
experiencing a problem I have not seen for a long time:
cpan> r
CPAN: Storable loaded ok
Going to read /Users/jd/.cpan/Metadata
Database was generated on Fri, 03 Feb 2006 02:17:31 GMT
CPAN: LWP::UserAgent loaded ok
Fetching with LWP:
ftp://cpan.etla.org/pub/CPAN/authors/01mailrc.txt.gz
LWP failed with code[404] message[File '01mailrc.txt.gz' not found]
Fetching with Net::FTP:
ftp://cpan.etla.org/pub/CPAN/authors/01mailrc.txt.gz
Couldn't fetch 01mailrc.txt.gz from cpan.etla.org
Fetching with LWP:
ftp://cpan.teleglobe.net/pub/CPAN/authors/01mailrc.txt.gz
Useless content call in void context at
/usr/local/lib/perl5/site_perl/5.8.7/LWP/Protocol/ftp.pm line 398
LWP failed with code[400] message[FTP return code 000]
Fetching with Net::FTP:
....
This is repeated for each of the sites in my list with a very long
wait for each failure. when all these fail it uses curl and
immediately gets the required files:
Trying with "/usr/bin/curl -L" to get ....
The last time I had this trouble, more than a year ago, I seem to
remember resolving it by reinstalling libnet or something, but I'd
like to know the proper way to put this right and what is causing it.
JD
Robert Whittle - 25 Jan 2006 10:32 GMT
Thanks for the detailed and useful info provided. When using the efax
approach described, is there any record available anywhere that tells
you whether or not the fax was successfully sent or not? Options to
retry if the number is busy ?
thanks
> I was intrigued by the original question and have done some
> experiments on this G4 running Mac OS X 10.4.4.
[quoted text clipped - 126 lines]
>>>
>>> A laudable aim.
Alan Fry - 25 Jan 2006 14:11 GMT
> Thanks for the detailed and useful info provided. When using the
> efax approach described, is there any record available anywhere
> that tells you whether or not the fax was successfully sent or not?
> Options to retry if the number is busy ?
There are return codes from 'efax' which tell you what transpired:
0 The fax was successfully sent or received.
1 The dialed number was busy or the modem device was in use. Try
again later.
2 Something failed (e.g. file not found or disk full). Don’t retry.
Check the session log for more
details.
3 Modem protocol error. The program did not receive the expected
response from the modem.
The modem may not have been properly initialized, the correct -o
options were not used, or a
bug report may be in order. Check the session log for more details.
4 The modem is not responding. Operator attention is required.
Check that the modem is turned
on and connected to the correct port.
5 The program was terminated by a signal.
I guess one would have to handle the return codes appropriately in
the perl script.
This, and much more information on the capabilities of 'efax' are all
to be found in the 'man pages': type 'man efax' into the Terminal
window.
HTH