Skip to content

Instantly share code, notes, and snippets.

@atduskgreg
Created March 22, 2012 16:50
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 atduskgreg/2159588 to your computer and use it in GitHub Desktop.
Save atduskgreg/2159588 to your computer and use it in GitHub Desktop.
A ruby program to automatically print new files that are added to a folder
drawings_path = "/path/to/folder/of/images/you/want/to/watch"
def most_recent_file(path, ext)
files = `ls -ctq #{path}`.split("\n").select{|f| f=~ /\.#{ext}/}
files.first
end
newest = most_recent_file(drawings_path, "jpg")
while true do
to_print = most_recent_file(drawings_path, "jpg")
if to_print != newest
sleep 1
puts "printing #{to_print}"
# replace the path to the printer.app here with yours
`open -a ~/Library/Printers/HP\\ LaserJet\\ P3005.app #{to_print}`
newest = to_print
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment