Created
January 22, 2020 18:42
-
-
Save dreamcat4/4240184f9299b211d2106bfef2d55518 to your computer and use it in GitHub Desktop.
4x6 inch label printer - pdf watch folder - on ubuntu, with lprint
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is a user land systemd service. Put it in your ~/.config/systemd/user/ folder | |
# Then: | |
# systemctl --user enable ebay-label-print.service | |
# systemctl --user restart ebay-label-print.service | |
# journalctl -f | grep label-print | |
[Unit] | |
Description=4x6 inch label printer - pdf watch folder - on ubuntu, with lprint | |
After=network.target | |
[Service] | |
Type=simple | |
Restart=on-failure | |
RestartSec=3 | |
PrivateTmp=true | |
# NoNewPrivileges=true | |
# NoNewPrivileges=false | |
ExecStart=/path/to/listen-folder-ebay-label-print-pdf.sh | |
ExecReload=/bin/kill -HUP $MAINPID | |
[Install] | |
WantedBy=default.target |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# enable shell trace debugging | |
set -x | |
# This script is optimized for ebay 4x6 inch pdf labels | |
# It requires the commands 'convert' from imagemagick and 'inotifywait' from inotify-tools | |
# 'sudo apt install -y inotify-tools' | |
# watch folder location | |
_listen_path="/home/YOUR_USER_NAME/PATH/TO/WATCH/FOLDER" | |
run_lprint_server() | |
{ | |
lprint server | |
} | |
_ebay-label-convert-pdf-to-png() | |
{ | |
_input_pdf="$1" | |
_output_png="${1}.png" | |
convert -density 320 "$_input_pdf" -scale 926x1463 -type grayscale -depth 8 -crop 812x1218+52+166 "$_output_png" | |
echo "saved $_output_png" | |
} | |
ebay-label-print() | |
{ | |
_input_pdf="$1" | |
_output_png="${1}.png" | |
_ebay-label-convert-pdf-to-png "$_input_pdf" | |
lprint -o media-top-offset=3.5mm -o print-color-mode=bi-level -o media-tracking=continuous -o media-type=labels-continuous -o media=oe_4x6-label_4x6in -o orientation-requested=portrait "$_output_png" | |
} | |
print-pdf-folder-listen() | |
{ | |
mkdir -p "$_listen_path" | |
cd "$_listen_path" | |
inotifywait -m "$_listen_path" -e create -e moved_to | | |
while read path action file; do | |
echo "The file '$file' appeared in directory '$path' via '$action'" | |
if [ "$file" != "${file%pdf}" ]; then | |
# do something with the file | |
ebay-label-print "$file" | |
rm -rf "$file" "$file.png" | |
fi | |
done | |
} | |
run_lprint_server & | |
print-pdf-folder-listen | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment