Skip to content

Instantly share code, notes, and snippets.

@keegoo
Last active September 5, 2022 09:04
Show Gist options
  • Save keegoo/774022d470742f12801a014f95b137b8 to your computer and use it in GitHub Desktop.
Save keegoo/774022d470742f12801a014f95b137b8 to your computer and use it in GitHub Desktop.

macOS Printer

根据wiki的定义,CUPS (Common Unix Printing System) 是一个专为类Unix系统开发的模块化打印系统。 它把运行CUPS的本地机器当作一个打印服务器。这个打印服务器接收来自同网络的其他client computers发来的print jobs,然后处理并把jobs发送给打印机。

在处理这些jobs的时候,CUPS会使用最佳的程序(filters, printer driveres, port monitors and backends)来把当前的页面转换成可打印的格式。

打印服务器、client computers和打印机之间的沟通就用到了IPP (Internet Printing Protocol)协议。根据wiki,协议的内容简单如下:

  • 支持client端(computers, mobile phones, tablets等)向打印机或打印服务器发送print jobs。
  • 查询打印机的状态。
  • 新建、删除和查询print jobs。
  • 因为IPP是基于IP-based的协议(意味着具有IP地址和端口<631>),所以也要支持权限管理,加密等功能。

如今市场上的打印机大部分(over 98%)都支持IPP协议,意味着你不需要装驱动就可以拥有基本的打印功能。

2007年2月份,苹果公司雇用了Michael Sweet(CUPS的创立者)并买下了CUPS的源代码。但在2019年12月Michael Sweet宣布离开苹果并基于那时的CUPS代码创立了OpenPrinting分支。所以在Github上如今可以找到Apple CUPSOpenPrinting CUPS两个版本的代码。两者都应该是基于IPP协议的。

CUPS提供了两个命令行工具用于获取打印相关的信息:lpstatlpinfo。这两个命令可以在macOS中找到。

  • lpstat - print CUPS status information.
  • lpinfo - show available devices or drivers.

例如:

# 显示打印机的信息
~$ lpstat -p
# output > printer EPSON_XP_2100_Series now printing EPSON_XP_2100_Series-14.  enabled since Sun Sep  5 15:17:26 2021
# note: 其中EPSON_XP_2100_Series-14指的是job ID.

# 显示打印机驱动的信息
~$ lpinfo -m
# output >
# ...
# Library/Printers/PPDs/Contents/Resources/EPSON WF-2830 Series.gz EPSON WF-2830 Series
# Library/Printers/PPDs/Contents/Resources/EPSON WF-2850 Series.gz EPSON WF-2850 Series
# Library/Printers/PPDs/Contents/Resources/EPSON XP-2100 Series.gz EPSON XP-2100 Series
# Library/Printers/PPDs/Contents/Resources/EPSON XP-3100 Series.gz EPSON XP-3100 Series
# Library/Printers/PPDs/Contents/Resources/EPSON XP-4100 Series.gz EPSON XP-4100 Series
# ...

来自AskDifferent的回复包含了许多有用的信息,摘录如下:

  • macOS下,打印机的驱动大多在/Library/Printers目录下。但CUPS并不强制驱动一定要在这个目录下。
  • 打印机驱动可以包含任意数量的文件。但这些文件必须注册在一个中心PPD文件中。(上网查了下,可惜没有找到这个PPD文件的位置)。

CUPS也有一个网络UI接口。输入如下命令,然后就可以通过浏览器访问: http://localhost:631/printers/

~$ cupsctl WebInterface=yes
@keegoo
Copy link
Author

keegoo commented Sep 5, 2021

macOS系统中,通过System Preferences -> Printers & Scanners可以来到配置打印机的界面。在这里我可以通过点击+按钮来选择并添加打印机。我使用的是EPSON XP-2101这款打印机,在打印机被添加上之后,我可以通过点击打印机提供的Options & Supplies -> Show Printer Web Page打开web界面来给打印机更新固件。

printer_setting

printer_general

@keegoo
Copy link
Author

keegoo commented Jun 7, 2022

发现EPSON XP-2101也可以用来扫描。可以到ESPON的官网下载XP 2101的Scanner Driver for MAC。安装后在Mac软件中会有一个叫Epson Scan 2的程序。打开程序并添加扫描仪就可以了。

Epson Scan 2

Epson Scan 2_2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment