How to determine which printers are turned on?

Is there any way to determine which printers are actually up and running? I want to be able to give the user a reminder to turn the printer on before complaining that a procedure doesn’t work.

Does it matter? If you print, it goes into the print queue until the printer is turned on.

I do not think the OS can tell, without sending some command to the printer that it can respond to.

It wouldn’t matter to you or me Bruce but I’m writing a system for a cattle breeder who’s not overly computer-literate and who expects a report to appear when she clicks on Button B. I’d like to minimise the opportunities for misinterpretation of the situation.

AppleScript can be used to set the default printer so I’d expect that it can also get a list of Printers. But even the Printers & Scanners control panel doesn’t indicate that a printer is on or off. They’re shown as Idle either way. My guess is that you can’t do it.

What you do is add a flag when Button B has been pressed and nothing else has happened. If she presses it again, the flag can interrupt the procedure by putting up a message to tell her to turn on the printer.

I thought I had found an easy solution for this problem when I noticed some discussion of the lpstat -p unix command and a claim that it would indicate if a printer was turned off or not connected. Alas, not so in the Terminal app on my system (10.13.6). On or off made no difference in the command’s output. I did discover however that there was an indicator that the printer was not connecting after a print job was sent and then, after a pause, the lpstat -p command was sent again. Here is the test code I used to send a small print job to my default printer and then checking to see if it connected properly. After the pause for 10 seconds I get the name of the default printer and then check to see the status. If the return ends with “Looking for printer.” I assume the printer is turned off. Note that with a shorter pause I sometimes got a different return like “Connecting to printer.”

printtopdf "","printer",""
let thePause=now()
let theOutput=""
loop
    nop
until now()>thePause+10
let defaultPrinter=array(shellscript({lpstat -d}),2,": ") 
shellscript {lpstat -p }+defaultPrinter,theOutput
if arraylast(theOutput,¶) contains "Looking for printer."
    message "Please turn on your printer."
Endif

Some things to keep in mind:

  1. I’m not sure the returned text is universal regardless of the printer used (mine is an Epson WF 2540).
  2. The delay may have to be adjusted depending upon the size of the print job (or possibly checking to see if the job has been entered in the print queue using lpstat -o…I have not check this for feasibility.)
  3. Maybe the whole scheme is not worth the trouble. :crazy_face:

This has been an interesting can of worms. Thanks to all, especially Gary who, as usual, has gone the extra mile. A quick test gives the following values for arraylast(theOutput,¶) when the printer is turned off:

Brother Mono Laser:
5 The printer is not responding.
6 The printer is not responding.
7 Connecting to printer.
8 Connecting to printer.
10 Connecting to printer.
20 The printer is not responding.
30 The printer is not responding.

Canon Inkjet Colour:
5 printer Canon_MX920_series is idle. enabled since Wed Jun 12 16:35:15 2019
10 printer Canon_MX920_series is idle. enabled since Wed Jun 12 16:35:15 2019
30 printer Canon_MX920_series is idle. enabled since Wed Jun 12 16:35:15 2019

where the first figure (5, 6, 30, etc) is the time delay set in Gary’s code.

When both printers are turned on and the job goes to the Brother, I still get the same Canon message as above.

Clearly more work to be done. I’m leaning towards Bruce’s observation - “Does it matter?”

It’s possibly a moot point now as far as this thread goes, but keep in mind that in Panorama X you can use the starttimer statement instead of a loop like this to delay. The huge advantage is that Panorama isn’t stuck while you’re waiting for something to happen, you can do other things. When you just want to delay, set the repeat to 1 and next to the time you want to delay (for example supernow()+10 for ten seconds). Using starttimer would also make it more practical to wait more than ten seconds.

Here is another approach but it requires that you know the IP address of the printer. The only way I could find my IP address was in the control panel on my printer itself. There were other methods mentioned online but none of them worked for me. Anyway, here is a scheme that uses the ping command to contact the printer’s IP address and see if it returns and error which would indicate the printer is not connected. The -c option in the ping command limits it to only 5 attempts to keep it from running forever.

seterror ""
shellscript {ping 10.0.1.4 -c 5}
If error
    message "Printer is turned off or not connected!"
endif
If info("error") = ""
    message "Printer online!"
endif

Most likely you would be better off using one of the previous suggestions or simply put up a reminder dialog before printing to make sure they have the printer turned on.

FWIW, I use the app ‘IP Scanner’ created by ‘10base-t interactive’. There are several version, free and paid, in the Apple store. Depending on how curious you are as to your network, these can be fun, interesting, and down right necessary. (To make sure you are getting the ones I’ve found useful, the apps icon looks like a radar screen.)

The IP Scanner app does the job - thanks Robert. But I wonder if the IP address is always the same? I’ve had occasions when the IP address of a device has changed from one session to another. Maybe it was the computer itself.

You have an option when setting up a printer, computer, or server, etc to have it be Static or Dynamic. I most often set up my printers and servers as static.