Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pklaus/b3a7f56f2886ed2d98c9313303554353 to your computer and use it in GitHub Desktop.
Save pklaus/b3a7f56f2886ed2d98c9313303554353 to your computer and use it in GitHub Desktop.
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 https://github.com/pklaus/brother_ql
# 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
break
fi
sleep ${i}s
done
if [ "$LBLPADDR" == "" ]; then
echo "Error, printer not found using Avahi."
return 2
else
brother_ql_print --backend network <( brother_ql_create --model ${LBLPMODEL} --label-size ${LBLPSIZE} "$1" ) tcp://${LBLPADDR}
fi
else
echo "Prints a black and white PNG to a networked Brother label printer."
echo "See https://github.com/pklaus/brother_ql for details."
return 1
fi
}
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