Automate checking local and network printers for last date used?

The winter air is very dry during our northern Colorado winters, so I want to be sure our printers get used at least weekly to keep the ink flowing.

I’ve been going to System Prefs > Printers and Scanners, selecting the printer, Open Print Queue to start the printer app, then Cmd 2 to show completed jobs, then scrolling to the bottom to see when it was last used.

Is there a way to automate this? I’d especially like to avoid going upstairs, commandeering my wife’s iMac, and going through all this there, in addition to checking my Mac in my basement studio. Maybe her Mac could be scheduled to send me a weekly report? She’s technophobic, so it would have to be completely invisible to her. :wink:

Thanks,
Russell

Luckily, Macs use CUPS, the Common Unix Printing System, and it has a web interface that runs on your Mac itself. To make all of the CUPS web interface available, run

cupsctl WebInterface=yes

in Terminal. Then you should be able to see a table of all jobs (like what you see using ⌘2 in the Print Queue) by sending your browser to

http://localhost:631/jobs?which_jobs=all

An automation-friendly way to get this list is to use curl to save the HTML file from the CUPS interface to your Desktop:

curl http://localhost:631/jobs?which_jobs=all > ~/Desktop/cups.html

There are lots of ways to set up an automation to run this command and then email the cups.html file to yourself. The “best” way is whatever you feel comfortable with: AppleScript, Keyboard Maestro, shell scripting, etc. If you’re feeling ambitious, you could parse the HTML table, extract the last line (which is the most recent print job), and email yourself just that line.

2 Likes

Thanks for such a helpful response! I recall messing around with CUPS (and Gutenprint) several years ago when trying to get my dinky HP inkjet to use the black cartridge only. I’ll try this over the weekend.

Best,
Russell

The CUPS jobs list worked great!

Now I’m trying to automate this, but when I run

curl http://localhost:631/jobs?which_jobs=all > ~/Desktop/cups.html

in Terminal, I get:

zsh: no matches found: http://localhost:631/jobs?which_jobs=all
rcb@Studio ~ %

…and no cups.html file lands in the Desktop folder.

What might be causing this? If I can get this working, I’m comfortable with running this from Keyboard Maestro.

Thanks again,
Russell

I don’t use zsh, so I may be way off here, but I suspect it sees the question mark in the URL as a wildcard. Try putting the URL in single quote marks.

That fixed it, however, the resulting file is the first html file of a multi-page report, with buttons for subsequent pages that don’t do anything. Is there a parameter I could add that would put it all in one file, or get just the last page? Or even every page as a separate file?

But this isn’t a big deal if the answer requires research. You kindly showed me how to query manually, and that’s quite enough!

Best,
Russell

2021-05-09-1225-55