Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

10.3: Fax from command line (or AppleScript) System
I was working on this to be able to fax from Filemaker with FM scripting and AppleScripting. I needed to print to a file (a .ps file), then send the resulting file to the fax. Fax is actually a CUPS print queue, and I just needed to find the proper command to send with a do shell script command in AppleScript.

The fax command, after much digging and trial and error, is:
 lp -d cups_queue_name -o phone=number filename
-d lets you specify the print queue to use, -o is indicating that you are sending options to the printer; in this case the phone number to fax to. My fax queue name is Internal_Modem (I used lpstat -p -d in the Terminal to find the appropriate queue name) so the command I used to fax a document from my desktop is:
 lp -d Internal_Modem -o phone=222-3333 ~/Desktop/filename.ps
This sent the fax to the fax queue just like using the Fax... button on the Print dialog. So now all I have to do is construct the appropriate do shell script command in an AppleScript (I did this in a FileMaker script step). Also, there likely is a way to set all of the options that are available in the Fax dialog, but all I needed was to get the phone number to the print command, as I had formatted the coverpage with the FileMaker layout.
    •    
  • Currently 1.57 / 5
  You rated: 2 / 5 (7 votes cast)
 
[19,034 views]  

10.3: Fax from command line (or AppleScript) | 14 comments | Create New Account
Click here to return to the '10.3: Fax from command line (or AppleScript)' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
10.3: Fax from command line (or AppleScript)
Authored by: fenner on Dec 05, '03 01:00:49PM
While writing an Apple FAX to HylaFAX gateway, I came across the following other options:

-o faxCoverSheet
-o faxSubject="Subject of the FAX"
-o faxCoverSheetMessage="Message for cover sheet"
-o faxTo="Person Receiving FAX"
To be honest, I haven't played with Apple's built-in FAX sending and receiving, only the ability to queue to a remote FAX server. Some of my work (including the PPD and instructions for queueing FAXes to a remote Panther FAX server) is available at http://www.electricrain.com/fenner/RemoteFax0.1.dmg. I'm interested in feedback from others since so far it's just been me experimenting with this.

[ Reply to This | # ]
plain text to postscript
Authored by: macubergeek on Dec 07, '03 12:04:19PM

I'm guessing this hint requires that you have a text file in .ps or postscript form. How do you convert plaintext-->postscript?



[ Reply to This | # ]
10.3: Fax from command line (or AppleScript)
Authored by: buzzdk on Dec 08, '03 06:46:07AM

I am having great dificulties with the cover sheet. Only the first word of faxSubject, faxCoverSheetMessage & faxTo are being transfered :-/

Anyone got a solution?



[ Reply to This | # ]
10.3: Fax from command line (or AppleScript)
Authored by: fenner on Dec 08, '03 10:58:13AM
Try URL encoding the options, e.g.

-o faxSubject="Hello%20my%20dear%20fax%20destination"
Sorry that I forgot this detail in my original followup.

[ Reply to This | # ]
Elaborate a bit...please
Authored by: jbc on Jan 07, '04 11:34:50PM

You say "I came across the following other options". Where?

I just installed Panther this week, and I'm looking at trying to replace an automated fax script using efax with using Apple's Fax from a shell script. Currently I have to enable "at" in the crontab in order to schedule faxes to go out at night. Is a setting for Apple's Fax Scheduler listed among the options you found?



[ Reply to This | # ]
10.3: Fax from command line (or AppleScript)
Authored by: bugugly on Mar 10, '05 02:44:53PM
Great stuff. Used your info and some php to create a www fax server that requires only a web browser to send faxes from our central server machine.

<?php
//make a file for testing, real world just pass in the filename
//and run from efix creation on down
define('FAX_FILE_LOCATION','/Users/Shared/createdfiles/');
$filename = date("ymdHis");
//create a file with no extension, extensions are hard to work with in efix
if ($newfile = fopen(FAX_FILE_LOCATION.$filename,"x"))//x for new file, fails if file exists
  {
	fwrite($newfile,"Making faxes baby!  From your friendly neighborhood WWW fax server! \n \n $filename");
	fclose($newfile);
  }
  else 
  {
	print("Could not create file, check permissions or file already exists");
  };

/**********Now efix to create a tiff G3 doc***********/
/**********see man efix for details******************/

$do_efix = exec("efix -n".FAX_FILE_LOCATION.$filename.".%03d ".FAX_FILE_LOCATION.$filename, $output, $returnValue);

if ($returnValue == 0)
  {
  $faxnum = '5555555555';
  /**Not sure if I need a wait state in here before setting up the fax**/
  print("<br>Fax starts in 5 seconds.....<br>");
  sleep(5);//just in case, give efix a little time
  //thanks to maxosxhints.com for lp -d -o stuff
  $dofax = exec("lp -d Internal_Modem -o phone=$faxnum ".FAX_FILE_LOCATION.$filename.".001",$output, $returnValue);
  //view results for debugging
  print("<br><hr>WWW fax server results: <br>\n");
  foreach ($output as $line)
  {
  print("$line<br>\n");
  }
  
  if ($returnValue== 0) {
  	print("<br>If you see a request ID your fax was successfully submitted with the job name listed under result. \n");
  	print("<br>Administrators can view this job from WWW by viewing CUPS print queue.");
    }
    else print("<br>Error submitting fax job, make note of results listed above");
  }

?>


[ Reply to This | # ]
10.3: Fax from command line (or AppleScript)
Authored by: ecallaghan on Jan 23, '04 07:26:29AM

We really have a need to fax invoices directly from FileMaker using Panther's new features. we have a bunch of invoices to different customers and need a solution to basicall loop through and fax them with no user intervention. Anyone have any applescripts etc that we can use?



[ Reply to This | # ]
Faxing in OS X using Applescript from Filemaker
Authored by: phowson on Feb 21, '04 06:58:05PM
Okay, so assuming we are doing this from within filemaker and we use values from the record to populate the following varialble for the do Applescript command:
number = the number of the person to whom we want to send the fax
PathToFile = path to the .ps file in the cue

It would look something like this:
lp -d Internal_Modem -o phone=number PathToFile

My questions are:

How do we generate the .ps file?
Could the same thing apply to generrating a PDF?

[ Reply to This | # ]

And the next hit on google after this one was:
Authored by: phowson on Feb 21, '04 07:32:38PM

http://developer.apple.com/technotes/tn2002/tn2082.html

Apparently Apple is ahead of us here. Looks like they have improved the print applescript command to allow for adjusting the CUPS settings from directly within the Applescript command. Handy.



[ Reply to This | # ]
And the next hit on google after this one was:
Authored by: ecallaghan on Nov 11, '04 05:03:18AM

Can you elaborate as to how to get filemaker to print a layout to a temp pdf (like the example in PDF Services on Apple.com where they print to email) and then fax it based on a field from FileMaker. Am I trying to get a square peg in a round hole or is it possible. I have one user who faxes MANUALLY 200 sheets a day after rpinting them out to 200 different companies. I want to automate this but am new to applescript and shell scripts and am at the moment shooting in the dark to get this working.

Many thanks



[ Reply to This | # ]
Found other 3 parameters
Authored by: wallybear on Oct 08, '04 11:35:54AM

While desperately seeking for disabling by default dial tone detection, I've discovered these other 3 options:

-o faxWaitForDialTone=false/true
-o faxUseSound=false/true
-o faxToneDialing=false/true

The first one does what I was looking for. It works from command line, but does not work as a key in prefs.



[ Reply to This | # ]
...Found!
Authored by: wallybear on Oct 08, '04 12:02:59PM

At last, I also found the key to add to Fax preferences to disable dial tone detection:
Just add this two lines in the Fax prefs (com.apple.print.FaxPrefs):

<key>modemInit-j</key>
<string>X3</string>

You can do it by hand or using the defaults command:

defaults write /Library/Preferences/com.apple.print.FaxPrefs modemInit-j X3

Finally I'll stop getting mad for having to disable it from the print panel every time I send a fax (it does not remember the setting).

This key will force disable Dial Tone detection, also if you see it enabled in the print panel.



[ Reply to This | # ]
10.3: Fax from command line (or AppleScript)
Authored by: ecallaghan on Nov 15, '04 04:56:18AM

Can you elaborate as to how to get filemaker to print a layout to a temp pdf (like the example in PDF Services on Apple.com where they print to email) and then fax it based on a field from FileMaker. Am I trying to get a square peg in a round hole or is it possible. I have one user who faxes MANUALLY 200 sheets a day after rpinting them out to 200 different companies. I want to automate this but am new to applescript and shell scripts and am at the moment shooting in the dark to get this working.



[ Reply to This | # ]
10.3: Fax from command line (or AppleScript)
Authored by: plehrack on Mar 31, '10 10:52:15AM
I tried:

lp -d Internal_Modem -o phone=222-3333 ~/Desktop/filename.ps

using my Multifunction Printer's queue and the file simply printed, it did not fax. Any thoughts?

Thanks,

Peter

[ Reply to This | # ]