Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Printing to a USB printer with Python on a Mac

I have a Star TSP600 thermal receipt printer attached to my macbook via usb. The drivers are installed, and I can print to it using the normal Mac print dialog.

How I can construct a program to send text to the printer? Is there a guide to basic printing interfaces? I generally work in Python, and I'd be willing to learn another language if it's appropriate for the task. Just looking for the basic "Hello World" example to get off the ground.

like image 785
Matt Hampel Avatar asked Sep 01 '09 20:09

Matt Hampel


People also ask

Can I use a USB printer on Mac?

For most USB printers, all you have to do is update your software and then connect the printer to your Mac. macOS automatically detects the printer and downloads any necessary software.

How do I connect to a printer in Python?

system("lpr -P printer_name file_name. txt") Where "printer_name" represents the name of the printer and "file_name. txt" is the name of the file that will be printed.


1 Answers

Take a look at the CUPS command line options.

Then you could use popen to send text to the printer.

#!/usr/bin/env python
import popen2
popen2.popen4("lpr -P [printer] " + output_file)
like image 136
Jonas Engström Avatar answered Sep 19 '22 12:09

Jonas Engström