Use cases
Use this skill when the user asks to print a local file, a just-generated file, a PDF, an image, or a document.
Core rules
- Before each print, you must confirm with the user:
- Paper size, default
A4 - Print color, default
黑白
- Paper size, default
- If the user has already clearly specified the paper and color in the same sentence, you may skip asking again.
- Do not submit a print job directly without confirming the paper and color.
- Before printing, first confirm that the file actually exists.
- Prefer the system default printer; if there is no default printer, list the available printers and let the user choose.
- If
lpstatcannot find a printer in the sandbox, retry with escalated permissions; this is usually restricted access to the macOS printing service and does not mean there is no printer.
Standard process
- Locate the file:
ls -lh "<file>"
- Query the printer:
lpstat -d
lpstat -e
lpstat -p
- Query the paper and color options supported by the target printer:
lpoptions -p "<printer>" -l
- Confirm the settings with the user. Recommended phrasing:
准备打印 <file> 到 <printer>。纸张用 A4、黑白打印,可以吗?
If the user wants to change them, accept common values:
| User wording | Common CUPS values |
|---|---|
| A4 | A4 |
| A5 | A5 |
| Letter | Letter |
| Black and white / grayscale | Gray or monochrome |
| Color | RGB or color |
- Submit the print job.
Prefer generic CUPS options:
lp -d "<printer>" -o media=A4 -o ColorModel=Gray "<file>"
If the printer does not support ColorModel=Gray, based on the output of lpoptions -p "<printer>" -l , switch to the actual options, for example:
lp -d "<printer>" -o media=A4 -o print-color-mode=monochrome "<file>"
lp -d "<printer>" -o media=A4 -o cupsPrintQuality=Draft "<file>"
- Report the job number and check the queue:
lpstat -W not-completed -o "<printer>"
lpstat -p "<printer>" -l
Reprint
If the user says "do it again/reprint/print another copy", check the queue first:
lpstat -W not-completed -o "<printer>"
- If the old job is still in the queue, first ask whether to cancel the old job to avoid duplicate printing.
- If the user clearly indicates that the old job failed, is being retried after running out of paper, or is stuck, cancel the old job and resubmit:
cancel "<job-id>"
lp -d "<printer>" -o media=A4 -o ColorModel=Gray "<file>"
Troubleshooting
- Hardware states such as red lights, out of paper, paper jams, and low ink can usually only be handled by the user on the printer; the CLI can only see the queue status.
lpstatshows the job staying innot-completed: prompt the user to check the paper, paper jams, ink, printer power, and USB/Wi-Fi connection.- When the printer is offline or paused, report the status first; do not repeatedly submit multiple jobs.
- If the user reloads paper and wants to print again: cancel the stuck old job, then submit a new job.
Common command quick reference
lpstat -d # 默认打印机
lpstat -e # 打印机名称列表
lpstat -p # 打印机状态
lpoptions -p "<printer>" -l # 支持的纸张/颜色/质量选项
lp -d "<printer>" -o media=A4 -o ColorModel=Gray "<file>"
lpstat -W not-completed -o "<printer>" # 未完成任务
cancel "<job-id>" # 取消任务