Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
General
GeneralPortable MacsHardwareNetworking
Applications
Mac ApplicationsEudoraFirefox / MozillaInternet ExplorerOutlook ExpressMS OfficeEntourageExcelPowerPointWordVirtual PCMedia PlayerOther MS Products
Programming
Mac ProgrammingCodeWarriorPerl
Country Specific
Australian Mac GroupUK Mac Group

Mac Forum / Programming / Perl / February 2006



Tip: Looking for answers? Try searching our database.

Faxing

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Bill Stephenson - 17 Jan 2006 19:29 GMT
Is there a way to fax a document using the built-in Mac OSX (10.3) fax
feature with perl?

I want to write a script that faxes selected members of congress my
humble opinions ;)

Kindest regards,
--
Bill Stephenson
Dominic Dunlop - 18 Jan 2006 07:29 GMT
> Is there a way to fax a document using the built-in Mac OSX (10.3)  
> fax feature with perl?

Well, the command-line program underlying the facility is efax.  
There's also a simplified front-end program, fax. You could try  
calling either of those with system() or whatever. Alternatively,  
CUPS makes the fax modem visible as a printer once it's configured --  
run  lpinfo -v  and you should see it listed. This means that you  
should be able simply to pipe the stuff you want to fax to lpr. The  
trick would be to work out what option you need to put on the command  
line in order to get the number dialled, and acceptable formats for  
the data. (Text is probably OK. Beyond that, I've no idea.)

Not that I've tried either possibility myself.

> I want to write a script that faxes selected members of congress my  
> humble opinions ;)

A laudable aim.
Signature

Dominic Dunlop

Robert Whittle - 18 Jan 2006 09:10 GMT
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. I could send HTML files, correctly formated, and there is a  
record kept which you can view in the GUI of all faxes send, or not.

If you do get something working, I'd  be very interested to know how  
you got it done

Robert Whittle

>> Is there a way to fax a document using the built-in Mac OSX (10.3)  
>> fax feature with perl?
[quoted text clipped - 16 lines]
>
> A laudable aim.
Adrian Hosey - 18 Jan 2006 13:22 GMT
: 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

Alan Fry - 23 Jan 2006 11:09 GMT
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
James Harvard - 18 Jan 2006 10:04 GMT
Don't know whether they use Perl or not, but you might find something ready-rolled in the source code for the following site. (It used to be 'faxyourmp.org.uk' so I assume there's fax code in there somewhere.)

http://www.writetothem.com/

Good luck,
James Harvard

>Is there a way to fax a document using the built-in Mac OSX (10.3) fax feature with perl?
>
>I want to write a script that faxes selected members of congress my humble opinions ;)
Doug McNutt - 18 Jan 2006 17:51 GMT
>I want to write a script that faxes selected members of congress my humble opinions ;)

You can send e-mail from perl and that leads to two options:

1) Send the email to efax (sp) where it can be converted to FAX and sent  for a fee.

2) Don't vote for representatives who steadfastly refuse to publish an e-mail address. I know, they will need a clerk to read it but that's true for the FAX too. Joel Hefley; are you listening?
Signature


--> Love your country. But don't trust its government. <--

Joseph Alotta - 18 Jan 2006 19:17 GMT
Hi Doug,

I like the idea of efax.  It seems good but costs $13/month.   That  
is a little high for me considering I send or receive about 5 faxes a  
year.  I wonder if there is another place that only charges when you  
do something?

>> I want to write a script that faxes selected members of congress  
>> my humble opinions ;)
[quoted text clipped - 7 lines]
> an e-mail address. I know, they will need a clerk to read it but  
> that's true for the FAX too. Joel Hefley; are you listening.

I was under the impression that all US representatives get an email  
address automatically assigned to them, whether they use it or not.

> --> Love your country. But don't trust its government. <--
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.