Jump to content

Workflow for printer status?


Recommended Posts

Posted

I'm looking for a workflow that reveals the status of the printers connected to one's computer. I work in an office with four communal printers, and inevitably 2 or even 3 of them are out of paper/jammed/otherwise malfunctioning. I can find that information out by going to the print center. But often when I'm about to print, I would like faster access to that information. It would be great to have a workflow where I could enter, say, "print" into Alfred and have a dropdown menu of my printers with their various statuses. Does anyone know if such a workflow exists (I haven't found it) or could anyone point me in the direction of Alfred workflow components that might get me toward building one? 

 

Thanks!

Posted

Ah thank you, this just might work! The "-a" command may be close to what I need (it shows when jobs were last accepted, and at least so far it aligns with whether the printer is working). However, I'm not sure how to build this into a workflow. I tried setting up a terminal command directly into a blank workflow, triggered by a keyword, but it looks like I need something a bit more complicated (like an SSH script) to get it to work through Alfred. Any pointers on how to do this? 

Posted

My understanding is that you would need to use a script filter and have it show your terminal results appear as multiple results in alfred. This is a little above my skillset but I wouldn't mind learning how this is done as well. I know that @Stephen_C has been branching out. Maybe he can help?

Posted (edited)

Crikey…don't land me in it! 😀

 

14 hours ago, macrospect said:

I tried setting up a terminal command directly into a blank workflow

Don't use a terminal command: use a shell script. Open Alfred's Run Script action, keep it set to /bin/zsh --no-rcs, delete the existing (greyed out) script and try typing in the relevant lpstat command…the result of which you'll then need to feed to an action to display the result (like a notification of Large Type action).

 

That's a pretty basic guide and if you need more help just post back and a Real Expert (TM) will come along and help.

 

Edit: Actually, that does work rather well for me. 😁

 

Stephen

Edited by Stephen_C
Further comments
Posted (edited)

oh yeah that is a very easy solution!!!

 

I'm curious though -- is there a simple way to take that very simple shell script that will output multiple lines and have them in a script filter and output multiple lines within the alfred window? Just for learning purposes.

Edited by sepulchra
Posted

I think we're getting into Vitor territory here (but I'm not going to flag him specifically as I suspect he's rather busy). I have a few workflows that have done that sort of thing (Find the weekday for example) but it's pretty much at the limit of my current understanding and I leaned heavily on stuff learned from Vitor.

 

Stephen

Posted

Well, you know I love a challenge, so here is something slapped together in a rather haphazard manner which may assist in doing the job.

Printer.thumb.png.d158b8113a819d63d988865450ce2e09.png

 

The code being this:

local_Printer=$(lpstat -d)
local_PrinterStatus=$(lpstat -a)
cat << EOB
{"items": [

  {
    "title": "$local_Printer",
    "subtitle": "$local_PrinterStatus",
    "arg": "$localPrinterStatus"
  }
]}
EOB

 

That will show the system default printer and the status of it. Clearly it's nothing more than a start for the original poster for it caters only for the system default printer and not an array of printers. However, it may assist in providing a start for something more sophisticated.

 

Stephen

Posted

Thanks so much for these ideas. Steven, I'm not sure I can get your script filter to work, though. It is showing up within Alfred when I type in "printer," but it quickly flicks away and I can't select it. Do I need to attach it to something else in a workflow? 

Posted

Oh and yes, the largetype solution does work. Pretty basic question: Is there a way for me to make the type less large? I'd also like to filter it before display because for me it's really messy (includes super long names for the printers and unnecessary date information) but I think I can figure that out.

Posted
1 minute ago, macrospect said:

Do I need to attach it to something else in a workflow? 

No: it's stand-alone. Make sure everything is set up in the script filter exactly as shown in the screen shot. Open the debugger, run the script filter and copy and post all of the output here.

 

2 minutes ago, macrospect said:

Is there a way for me to make the type less large?

No—but you could use a Dialog Conditional instead (you'd need only a single OK button to dismiss it by pressing ⏎).

 

Stephen

Posted

I'm sorry, I got a bit delayed in replying to these posts because it turns out that this script doesn't actually correspond with the printers in my office (I had thought that the "accepting requests since" time corresponded to the time they had last completed a job, but that seems not to be the case; I'm not sure what info the readout offers). 

 

However, I'm still interested in figuring these issues out because I think it may help me to make other workflows, if you don't mind. 

 

Stephen @Stephen_C, here is the bug report for your printer script: 

 

[10:06:29.025] Printers_work[Script Filter] Queuing argument '(null)'
[10:06:29.232] Printers_work[Script Filter] Script with argv '(null)' finished
[10:06:29.235] Printers_work[Script Filter] {"items": [

  {
    "title": "system default destination: _10_136_40_246",
    "subtitle": "_10_136_40_246 accepting requests since Fri Feb 23 14:15:32 2024
_10_136_41_180 accepting requests since Thu Feb 22 10:55:50 2024
_422_1 accepting requests since Mon Feb 12 17:40:07 2024
_422_2 accepting requests since Thu Jan 25 13:06:13 2024
HP_LaserJet_MFP_M234dw__F8EEDE__20210915155717 accepting requests since Wed Feb 28 08:24:16 2024",
    "arg": ""
  }
]}
[10:06:29.237] ERROR: Printers_work[Script Filter] JSON error: Unescaped control character around line 5, column 81. in JSON:
{"items": [

  {
    "title": "system default destination: _10_136_40_246",
    "subtitle": "_10_136_40_246 accepting requests since Fri Feb 23 14:15:32 2024
_10_136_41_180 accepting requests since Thu Feb 22 10:55:50 2024
_422_1 accepting requests since Mon Feb 12 17:40:07 2024
_422_2 accepting requests since Thu Jan 25 13:06:13 2024
HP_LaserJet_MFP_M234dw__F8EEDE__20210915155717 accepting requests since Wed Feb 28 08:24:16 2024",
    "arg": ""
  }
]}

 

And @giovanni here's the output of the lpstat -a command. Is that possible to parse? I would be trying to convert the "_10_136_41_180" to "Color Printer 1" and the dates to relative (e.g., "Thu Feb 22 10:55:50 2024" --> "6 days ago"). Not sure if that's even possible!

 

_10_136_41_180 accepting requests since Thu Feb 22 10:55:50 2024
_422_1 accepting requests since Mon Feb 12 17:40:07 2024
_422_2 accepting requests since Thu Jan 25 13:06:13 2024
HP_LaserJet_MFP_M234dw__F8EEDE__20210915155717 accepting requests since Wed Feb 28 08:24:16 2024

 

Posted

Wow, @giovanni, this is amazing. Thank you. This also gives me a lot to learn from.

 

Also: I'm sorry, but I realized that there's actually another output, for the status of Color Printer 2 that was cut off in my copy/paste (actually, it's Color Printer 1 and the original I gave you is Color Printer 2). Can I just add/swap in the following code, or would I need to further change the script in some way? (It's not immediately working for me.)

 

do
printerName=$(echo $line | awk '{print $1}')
if [ "$printerName" = "_10_136_41_180" ]; then
    printerName="Color Printer 2"
fi

do
printerName=$(echo $line | awk '{print $1}')
if [ "$printerName" = "_10_136_40_246" ]; then
    printerName="Color Printer 1"
fi

Posted

remove the second 

do
printerName=$(echo $line | awk '{print $1}')

you can also replace the second if with elif, in which case you would need to delete the first fi

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...