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

A script to retain a copy of outgoing faxes System 10.5
For the few times I need to send a fax, I'm not going to mess with getting one of my broken third-party fax applications to run again. But the built-in OS X fax capability has some annoying limitations. One of the more annoying ones is that it doesn't save a copy of outgoing faxes. I wrote the following script as a kluge, to grab a copy of outgoing faxes and store them in /Users/Shared/Faxes/Outbox. The fax is saved (complete with the cover page) as a multi-page TIFF file.

if [ $EUID -ne 0 ]; then

dt=`date '+%Y%m%d-%H%M%S'`
echo Waiting for efax to run.
while [ x$t = x'' ]; do
	t=`ps -ef|grep efax|grep -v grep`
	sleep 1

ls -al /var/spool/cups/tmp
f=`echo $t|sed -e 's#.*\(/private.*\)#\1#'`
if [ -r $f ]; then
	echo COPYING $f to /Users/Shared/Faxes/Outbox/$dt.tiff
	cp $f /Users/Shared/Faxes/Outbox/$dt.tiff
	sudo chmod a+r /Users/Shared/Faxes/Outbox/$dt.tiff
	open /Users/Shared/Faxes/Outbox
	echo file $f doesn\'t exist

echo If something goes wrong, try \"faxlog debug\"
tail -f /var/log/cups/error_log
I saved the script as watch_fax, in a spot where my admin user could get to it. You have to sudo to run this script, because it has to copy from /private/var. Don't forget to make it executable with chmod u+rx watch_fax.

To run it, I type sudo watch_fax. This script ends with a tail -f, which will show you the fax log as it's being written. When you're done watching the fax log, you'll have to kill the tail with Control-C. This script also references another of my scripts, called faxlog, that helps you set debug mode for the fax log. You can find that script in this hint.

[robg adds: I haven't tested this one.]
  • Currently 1.86 / 5
  You rated: 5 / 5 (7 votes cast)

A script to retain a copy of outgoing faxes | 4 comments | Create New Account
Click here to return to the 'A script to retain a copy of outgoing faxes' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Oozing Race Conditions
Authored by: zeniam1 on Dec 11, '08 06:34:54AM

Although not dangerous, scripts like this rarely work correctly. There is no guarantee that efax will appear in your process listing -- it could have come and gone in less than a second. You also don't know when it is safe to pull a copy of the file from a CUPS directory. A better approach would be to offer a wrapped efax application script that would run instead of the original. The script would then call the original. I would bet that there would be some command line arguments that give you the location of the file to fax, allowing you to safely make copies without fear that the original gets moved or goes away.

[ Reply to This | # ]
Oozing Race Conditions
Authored by: xr4ti on Dec 16, '08 02:15:10PM
I've used this script half a dozen times, with 100% success. (Over the last 10 years, I've also used similarly constructed scripts, carefully applied, for unix admin purposes. If you know your target application, and test carefully, scripts like this can be reliable.)

The commenter may not have used common sense when concluding that efax could appear and disappear in less than a 1-second cycle. It it does, then your fax failed to be sent

Also, the script doesn't "pull" a copy, it makes a copy, leaving the original intact and unmolested.

And further, the script waits until the efax process is running which means the file being sent is safe to copy.

In my opinion, a wrapper would be a much worse idea. The next OS update could wipe your wrapper out, and you wouldn't know it until after you lost the chance to copy your next fax.

[ Reply to This | # ]

A script to retain a copy of outgoing faxes
Authored by: _mikk on Dec 11, '08 04:45:22PM

You might want to change




The best is to actually use #!/bin/sh

[ Reply to This | # ]
A script to retain a copy of outgoing faxes
Authored by: xr4ti on Dec 16, '08 02:31:13PM
The comment is correct, the initial '#' must have gotten dropped by the forum editing process (and the original author can't change it).

I don't see anything 'best' about using bash (what sh links to), rather than zsh. I prefer zsh because it behaves more like the ksh of SysV Unixes of old and has a feature set I prefer. But let's avoid diverging to a shell war, comparisons can be found at

[ Reply to This | # ]