Created
March 22, 2012 16:50
-
-
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
This file contains 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
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