Edited on January 1st, 1970, 00:00 UT.
I like my system to notify me of important events. Events could be anything: New ICQ Message, Star Trek is on TV in 15 minutes, CPU is going to melt into a puddle in 5 minutes, whatever. I often accomplish notification by playing the appropriate wave file.
It occured to me that it might be nice to know when a print job has completed. My HP DeskJet 722C photo printer is remarkably quiet. And, anyone who has printed photographs with an inkjet can tell you it takes a while. Even large low-color or monochrome print jobs can take quite some time. During such time I may wander away from the computer. Having some sound to summon me back to whatever I was doing seems like a good idea. I can always mute the sound if I don't want to hear it.
Any Linux, or Unix, system using LPD (Line Printer Daemon) using print filters can do this. For those which don't use LPD then you could make a wrapper around whatever command you use to print. I'll try to make this clear to you later on.
There are three popular ways to play sound bites on Linux. We will use esdplay in this example. All 3
utilities work alike and are designed to drop in place of one another. You can choose the one appropriate to your needs:
/usr/bin/play
/usr/bin/esdplay (or /opt/enlightenment/bin/esdplay)
/usr/bin/kplayaudio (or /opt/kde/bin/kplayaudio)
The tricky part may be finding your print filter. When you installed your printer(s) you gave it a name. You may have created
several configurations for one printer, each having a different name. The default printer is named lp (Line Printer).
To find the print filter look inside of the /etc/printcap file. You will see a listing similar to:
##PRINTTOOL3## LOCAL pnmraw 600x600 letter {} {HP DeskJet 720} ppa720c3 {}
lp:\
:sd=/var/spool/lpd/lp:\
:mx#0:\
:sh:\
:lp=/dev/lp0:\
:if=/var/spool/lpd/lp/filter:
##PRINTTOOL3## LOCAL pnmraw 600x600 letter {} {HP DeskJet 720} ppa720c1 {}
econo:\
:sd=/var/spool/lpd/econo:\
:mx#0:\
:sh:\
:lp=/dev/lp0:\
:if=/var/spool/lpd/econo/filter:
That may look scary, but, don't be intimidated. There are two printer listings shown. The first,
lp is the default photo quality filter, and, the second econo is an ink saver filter.
Only pay attention to the line which says :if=/var/spool/lpd/lp/filter:. That is the only thing you
need to know. /var/spool/lpd/lp/filter is the filter script for the lp printer entry.
Make a backup of the file before you do anything. I will not be held responsible for anything bad that happens. If you don't like that then stop reading.
Open the filter script, which we found was /var/spool/lpd/lp/filter, in your favorite text editor. Look
for a section at the very end of the script something like this:
#
# run the command!
#
eval $bestpath 2>/dev/null
#
# see if we need to send a form feed to eject the page from printer
#
# if [ "$SEND_EOF" != "" ]; then
# printf "\014"
# fi
exit 0
This is the section which executes the appropriate filter for the document you are printing. If your file looks different then read the comments and determine how it works. You only need to do a whack job; you don't need to understand how the whole script works.
I modified mine like this:
#
# Play Printing Started Sound
/usr/bin/esdplay /usr/share/sounds/print-start.wav &
#
# run the command!
#
eval $bestpath 2>/dev/null
#
# see if we need to send a form feed to eject the page from printer
#
# if [ "$SEND_EOF" != "" ]; then
# printf "\014"
# fi
# Play Printing Complete Sound
/usr/bin/esdplay /usr/share/sounds/print-complete.wav &
exit 0
After you have modified the script then test it as your normal user. Make sure the sound plays and you don't get any errors (control-C to kill). Then print a small test document to ensure it still prints and the sound plays. It took me a few tries because I made some dumb mistakes. I accidentally had the permissions set to rw------- (0600) on the wave files because I was in a hurry to get the sound working. Permissions should have been rw-r--r-- (0644).
You can add a start/complete sound to just about anything running in the foreground. If nothing else, you can write a wrapper
script to do the deed. We will use X as an example. My X executable is /etc/X11/X. Rename the original command
to something like /etc/X11/X.real. Then create a script named /etc/X11/X with the contents similar to:
#!/bin/sh # Play Startup Sound /usr/bin/play /usr/share/sounds/x-start.wav & # Start the Real X and pass command line args through with $* /etc/X11/X.real $* # Play Complete Sound /usr/bin/play /usr/share/sounds/x-complete.wav &
Take advantage of your shell rather than burden yourself with the task of rewriting a thousand scripts any time you change your preference.
Here I will modify the previous script to read the file name of the sound player from a .soundplay file in my home directory
using an environment variable and the cat (concatenate) command. The .soundplay file contains a single
line of text indicating the filename of my prefered sound player.
#!/bin/sh # Get our prefered sound player from the ~/.soundplay text file SOUNDPLAYER = `cat ~/.soundplay` # Play Startup Sound $SOUNDPLAYER /usr/share/sounds/x-start.wav & # Start the Real X and pass command line args through with $* /etc/X11/X.real $* # Play Complete Sound $SOUNDPLAYER /usr/share/sounds/x-complete.wav &
Have fun with sounds on your system. Use sound to bring things to your attention. If you choose your sounds carefully they can be a great benefit to you.