Skip to content

Add a Printers widget that reads printers over IPP - #24

Open
masonjmiller wants to merge 1 commit into
kemalandic:mainfrom
masonjmiller:printers-widget
Open

masonjmiller wants to merge 1 commit into
kemalandic:mainfrom
masonjmiller:printers-widget

Conversation

@masonjmiller

@masonjmiller masonjmiller commented Oct 7, 2026 •

Copy link
Copy Markdown

A native Printers widget (Network): the state, problems and ink levels of the printers on your network. Like the Cameras widget (#22), I built it with Claude.

The Printers widget on a XENEON EDGE showing All Printers: an Epson SC-F100 and an HP Smart Tank 6000, both Ready with green dots, and the HP's four ink bars in cyan, magenta, yellow and grey

What it does

  • Finds printers by itself. Every printer that works with AirPrint or Mopria appears, the same ones the Print dialog lists, with nothing to set up.
  • All Printers (the default) lists each printer with:
    • a status dot, which pulses while printing;
    • what it's doing or its most serious problem;
    • small ink bars.
  • One printer gives it the whole widget. Each ink tank or toner cartridge is drawn in the printer's own colour with its level, outlined in red when the printer says it's low.
  • In words. Ready, Printing · 2 waiting, Out of paper, Paper jam, Cover open, Ink low, and so on, from the printer's own state reasons.
  • Tap opens the printer's own web page, for its settings and supply details.
  • A printer that sleeps or switches off keeps its last status, with "Not responding" beside it.

The Printers widget set to the HP Smart Tank 6000: its name and Ready at the top, and four tall ink tanks in cyan, magenta, yellow and grey, each labelled 100% with its colour name underneath

How

  • IPP.swift is just enough of IPP (RFC 8010/8011) to send Get-Printer-Attributes and read the reply. It handles multi-value attributes and textWithLanguage, and skips collections. There's no CUPS and no third-party code.

  • PrinterStatus turns the reply into the widget's terms:

    • printer-state;
    • printer-state-reasons, with severity from the -error/-warning/-report suffix;
    • the marker-* attributes as supplies with names, levels and sRGB colours, where -3 means "some left";
    • printer-more-info for the tap.
  • PrinterService (ServiceKey.printers):

    • browses Bonjour for _ipp._tcp and _ipps._tcp, preferring IPPS when a printer offers both;
    • resolves each printer to an IPv4 address, stripping the interface that Network.framework appends ("192.168.1.20%en0" would make the URL invalid);
    • asks each printer every 30 s, or every 5 s while one is printing.

    A printer that answers plain IPP with HTTP 426 is asked again over TLS. PrinterTransport is injectable, so the tests run without a printer.

  • ConfigFieldType.printerPicker lists the printers found while the app runs, next to notePicker for the same reason: its options can't be in the schema. A chosen printer that's switched off stays in the list as "(not found)", so it doesn't quietly revert to All Printers.

  • Info.plist: NSLocalNetworkUsageDescription, plus NSBonjourServices for the two IPP types.

  • The printing colour is the widget's primary (cyan), settable on the Theme page like the other Network widgets.

Choices worth a look

  • The printer itself, not CUPS. Asking the printer directly sees every printer on the network, whether or not it's been added to this Mac, and reads the printer's own supply levels.
  • Printers' own certificates. Printers serve IPPS with certificates they made themselves, so these are accepted, as macOS's printing does. Only a status request goes out.
  • Polling. IPP has subscriptions, but support is uneven. Polling every 30 s, and every 5 s while printing, is light and works with every printer.

Testing

  • xcodebuild test passes in full: 415 Swift Testing tests in 40 suites, plus the XCTest suite. 28 of the tests are new, in three suites: IPP encoding and decoding, status interpretation, and the service, including the 426 retry and the scoped-address fix.
  • The fixtures are recorded IPP replies from an HP Smart Tank 6000 (four ink tanks) and an Epson SC-F100 (no supply levels), with addresses replaced.
  • On my network (macOS 27.2), the service found both printers over IPPS and read the HP's four ink levels and the Epson's state.
  • On a XENEON EDGE, the widget showed both printers in All Printers, and the HP on its own (the screenshots above).
  • Scripts/ci-local.sh all passes: the format check is clean and there are no compiler warnings.

Overlaps with #22

This touches the same places as #22 (Cameras):

  • ConfigFieldType, ServiceKey, AppModel and WidgetRegistry;
  • NSLocalNetworkUsageDescription;
  • the README's widget count;
  • the guide.

Whichever lands later, I'll rebase.

🤖 Generated with Claude Code

Printers are the other thing on a desk that wants watching: whether one is
ready, why it isn't, and how much ink is left before a job runs out of it.
Every printer that works with AirPrint or Mopria answers the same question
over IPP, the Internet Printing Protocol, so one small request covers nearly
every printer of the last decade with no driver, account or setup.

PrinterService finds printers the way the Print dialog does, over Bonjour as
_ipp._tcp and _ipps._tcp, and asks each for its attributes every 30 seconds,
every 5 while one is printing. Printers that refuse plain IPP with HTTP 426
are asked again over TLS; their certificates are ones they made themselves,
which macOS's own printing accepts too, and only a status request goes out.
A printer that stops answering keeps its last status, with the problem beside
it, because ink doesn't vanish when a printer sleeps.

IPP.swift is just enough of RFC 8010 to send Get-Printer-Attributes and read
the reply, skipping the collections and types the widget has no use for.
PrinterStatus turns the reply into words: the state, the most serious of the
printer-state-reasons ("Out of paper", "Cover open"), and the marker-*
attributes as supplies with names, levels and the printer's own sRGB colors.

The widget lists every printer, or gives one the whole tile with its ink
tanks drawn in their colors, outlined in red when the printer says one is
low. A tap opens the printer's web page. A new config field type,
printerPicker, lists the printers found while the app runs, and keeps a
chosen printer in the list while it is switched off.

The tests read recorded replies from an HP Smart Tank and an Epson SC-F100.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@masonjmiller
masonjmiller marked this pull request as ready for review October 8, 2026 16:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant