Skip to content

Instantly share code, notes, and snippets.

@seven1m
Last active March 30, 2018 18:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seven1m/a6792af8618ac907cafce1142e6c4eba to your computer and use it in GitHub Desktop.
Save seven1m/a6792af8618ac907cafce1142e6c4eba to your computer and use it in GitHub Desktop.
Speed up printing to Dymo printers on macOS High Sierra by killing hung processes.
# Problem:
#
# There is a 10-12 second delay between each print job when printing labels on a Dymo LabelWriter
# (and probably other Dymo printers) via newer versions of Cups. This affects macOS High Sierra,
# Raspbian Linux, and probably other Linux distributions.
#
# This script is a hack to work around the problem by killing hung print processes once the label is finished printing.
#
# Script Usage:
#
# sudo ruby dymo_speed.rb
#
# This is what you see when Dymo is printing:
#
# $ ps aux | grep -i dymo
# lp 6428 4.5 0.5 13244 5012 ? S 18:03 0:00 DYMO_LabelWriter_450 63 ...
# root 6429 3.0 0.4 37684 4596 ? Sl 18:03 0:00 usb://DYMO/LabelWriter%20450?serial=...
#
# This is what you see when the Dymo driver is sleeping, preventing the next print job from running:
#
# $ ps aux | grep -i dymo
# root 6429 3.0 0.4 37684 4596 ? Sl 18:03 0:00 usb://DYMO/LabelWriter%20450?serial=...
#
# When the second scenario is witnessed, kill -9 the driver so the next job can be processed.
#
loop do
printing = false
driver_pid = nil
`ps aux | grep -i dymo`.split(/\n/).each do |line|
parts = line.split
pid = parts[1]
name = parts[10]
printing = true if name =~ /DYMO_/
driver_pid = pid if name =~ %r{usb://}
end
if driver_pid && !printing
`kill -9 #{driver_pid}`
puts "#{driver_pid} was killed"
end
sleep 0.1
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment