Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Bash function to print black and white PNG (and JPEG, GIF, BMP) files to a networked Brother label printer (such as the QL-720NW)
# Print a black and white PNG file on the first available Brother label printer
# Requires
# Source (.) this file to set bash completion and add the print function.
function print-png-label() {
if [ -f "$1" ]; then
# Change these to match your printer:
local LBLPMODEL="QL-720NW"
local LBLPSIZE="62"
# Query a bunch of times to allow the printer to wake up.
for i in {1..5}; do
local LBLPADDR=$(avahi-browse --resolve -t -p "_pdl-datastream._tcp" | grep ${LBLPMODEL} | egrep -m 1 "^=" | awk -F ";" '{print $8 ":" $9}')
if [ ! "$LBLPADDR" == "" ]; then
sleep ${i}s
if [ "$LBLPADDR" == "" ]; then
echo "Error, printer not found using Avahi."
return 2
brother_ql_print --backend network <( brother_ql_create --model ${LBLPMODEL} --label-size ${LBLPSIZE} "$1" ) tcp://${LBLPADDR}
echo "Prints a black and white PNG to a networked Brother label printer."
echo "See for details."
return 1
complete -f -X '!*.@(bmp|dcx|gif|jpe|jpeg|jpg|png|ppm|tif|tiff)' print-png-label
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment