Displaying your printer’s status

(2012-10-28)

At our house, we have a single, high-quality laser color printer in the basement (along with the other computer equipment) which everybody uses, as opposed to a crappy cheap printer at everyone’s workplace. This is a great setup in our situation, since nobody prints a lot individually, so the slight discomfort of having to go to the basement is a welcome trade-off for not having to maintain cheap printers.

The only problem with this is the lack of feedback from the printer. That is, when you printed your document from, say, your web browser, you have no way of knowing when printing finished. Sure, you could go to the CUPS print server and repeatedly watch to know when CUPS finished spooling the job. But that’s rather inconvenient and won’t tell you what’s wrong in case the printer does not print as expected (it will just sit there, or be paused).

What happened in reality is that I send the print job, wait a certain amount of time (roughly corresponding with the document size) and just walk into the basement. That usually works, except when it doesn’t.

Therefore, I wrote a little script which will display the printer’s status (effectively what it displays on the LCD) using a Freedesktop notification whenever the status changes. It looks like this in action:

printer status screenshot

…where "kyocera" is the hostname of the printer and "Es wird gedruckt" is the german way of saying "printing". The program displaying the notification is dunst, a dmenu-ish notification-daemon which I can recommend.

You can find the script called notify-printer-status here (how creative, eh?). Since the source code is only 44 lines long (including comments and boilerplate), adding configuration logic seems to be overkill. Instead, just modify your copy of it. I’ve been using the script since over a month and it’s been working fine, so I doubt there are any serious bugs in the code.

To use it, you first need an SNMP-capable printer (doh). Then, install the Perl modules Net::SNMP and Desktop::Notify (sudo apt-get install libnet-snmp-perl libdesktop-notify-perl on Debian). Now replace the hostname and find out the SNMP OID for your printer. This is surprisingly hard, but one way I’ve found to work well for me is to use snmpwalk, distributed as an example with Net::SNMP, and grep for what the printer currently displays:

$ zcat /usr/share/doc/libnet-snmp-perl/examples/snmpwalk.pl.gz > snmapwalk.pl
$ perl snmapwalk.pl kyocera.rag.lan | grep Ruhemodus
1.3.6.1.2.1.43.16.5.1.2.1.1 = OCTET STRING: Ruhemodus

Afterwards, just start the script in your ~/.xsession and forget about it. Enjoy!