网淘吧来吧,欢迎您!

Printer skill

2026-04-01 新闻来源:网淘吧 围观:68
电脑广告
手机广告

打印机 (CUPS)

使用 macOS 内置的 CUPS 命令控制打印机。无需外部 CLI。

发现打印机

# Network printers (Bonjour/AirPrint)
dns-sd -B _ipp._tcp . 2>/dev/null & sleep 3; kill $! 2>/dev/null

# Get printer details (host, port, resource path)
dns-sd -L "Printer Name" _ipp._tcp . 2>/dev/null & sleep 3; kill $! 2>/dev/null

# CUPS-native discovery
lpstat -e                         # available network destinations
lpinfo --include-schemes dnssd -v # dnssd backends

# IPP discovery
ippfind --timeout 5

添加打印机(免驱动 IPP Everywhere)

# Recommended: driverless queue
lpadmin -p MyPrinter -E -v "ipp://printer.local:631/ipp/print" -m everywhere

# Set as default
lpadmin -d MyPrinter

# Enable SNMP supply reporting (toner levels)
sudo lpadmin -p MyPrinter -o cupsSNMPSupplies=true

打印文件

lp filename.pdf                      # to default printer
lp -d MyPrinter filename.pdf         # specific printer
lp -d MyPrinter -n 2 file.pdf        # 2 copies
lp -d MyPrinter -o sides=two-sided-long-edge file.pdf  # duplex
lp -d MyPrinter -o media=letter file.pdf
lp -d MyPrinter -o ColorModel=Gray file.pdf  # grayscale

# Print text directly
echo "Hello World" | lp -d MyPrinter

队列管理

# Check status
lpstat -p MyPrinter        # printer status
lpstat -o MyPrinter        # queued jobs
lpstat -t                  # everything
lpq -P MyPrinter           # BSD-style queue view

# Cancel jobs
cancel JOB_ID
cancel -a MyPrinter        # cancel all

# Enable/disable
cupsenable MyPrinter       # resume printing
cupsdisable MyPrinter      # pause printer
cupsaccept MyPrinter       # accept new jobs
cupsreject MyPrinter       # reject new jobs

打印机选项

# List available options for a printer
lpoptions -p MyPrinter -l

# Set default options (per-user)
lpoptions -p MyPrinter -o sides=two-sided-long-edge

# Set server-side defaults
sudo lpadmin -p MyPrinter -o sides-default=two-sided-long-edge

状态与诊断

# IPP status query (detailed)
ipptool -t ipp://PRINTER_IP/ipp/print get-printer-attributes.test

# Filter for key info
ipptool -t ipp://PRINTER_IP/ipp/print get-printer-attributes.test \
  | grep -iE 'printer-state|marker|supply|media|error'

将打印机从睡眠中唤醒

# IPP poke (usually wakes the printer)
ipptool -q -T 5 ipp://PRINTER_IP/ipp/print get-printer-attributes.test

# HTTP poke (wakes web UI stack)
curl -s -m 5 http://PRINTER_IP/ >/dev/null

# TCP connect test
nc -zw2 PRINTER_IP 631

保持活跃(防止深度睡眠)

# Poll every 5 minutes (runs in foreground)
ipptool -q -T 3 -i 300 ipp://PRINTER_IP/ipp/print get-printer-attributes.test

如需持续保持活跃,请创建一个 launchd 代理。

Printer skill

通过 SNMP 查看碳粉余量

需要brew install net-snmp

snmpwalk -v2c -c public PRINTER_IP 1.3.6.1.2.1.43.11.1.1

注意:打印机上可能禁用了 SNMP。请检查远程用户界面设置。

远程用户界面(网页界面)

大多数网络打印机在http://打印机IP地址/地址下提供网页用户界面,可用于:

  • 睡眠/定时器设置(设置 > 定时器设置 > 自动睡眠时间)
  • 网络协议配置(启用/禁用IPP、SNMP、原始9100端口)
  • 耗材状态

故障排除

# Printer stuck/disabled? Re-enable it
cupsenable MyPrinter

# Check device URI
lpstat -v MyPrinter

# Remove and re-add printer
lpadmin -x MyPrinter
lpadmin -p MyPrinter -E -v "ipp://..." -m everywhere

# CUPS error log
tail -f /var/log/cups/error_log

注意事项

  • 首选ipp://ipps://URI而非原始9100端口或LPD协议
  • -m 参数适用于所有场景根据打印机的IPP功能自动配置
  • 选项名称因打印机而异;使用lpoptions -l命令进行查询
  • 睡眠设置建议通过打印机远程界面配置
  • 自动睡眠(1分钟)保持服务活跃 - 打印任务会自动唤醒打印机
  • 若打印机完全无响应(IPP端口关闭、HTTP连接超时),可能处于深度睡眠或已关机。请通知用户现场检查/唤醒打印机。

免责申明
部分文章来自各大搜索引擎,如有侵权,请与我联系删除。
打赏

文章底部电脑广告
手机广告位-内容正文底部
上一篇:Salesforce 下一篇:GlobePilot AI Agent 2

相关文章

您是本站第387672名访客 今日有1篇新文章/评论