Skip to content

Instantly share code, notes, and snippets.

@qoobaa
Created October 20, 2011 18:19
Show Gist options
  • Save qoobaa/1301868 to your computer and use it in GitHub Desktop.
Save qoobaa/1301868 to your computer and use it in GitHub Desktop.
start on startup
exec /usr/local/bin/scanner.rb
#!/usr/bin/ruby
require "sane"
require "fileutils"
require "tempfile"
loop do
scan = nil
begin
Sane.open do |sane|
device = sane.devices.find do |device|
device.vendor == "Canon" && device.model == "LiDE 100"
end
if device
device.open do
while scan.nil?
if device[:file]
scan = ["--device", device.name,
"--mode", "Lineart",
"--resolution", "300"]
end
sleep(0.5)
end
end
end
end
rescue Sane::Error => exception
end
if scan
tempfile = Tempfile.new("scan")
tempfile.close
system("scanimage", *scan, :out => tempfile.path)
output_dir = "/nfs/media/Scans"
FileUtils.mkdir_p(output_dir, :mode => 0777)
output_file = "#{output_dir}/#{Time.now.strftime("%Y%m%d%H%M%S")}.png"
system("convert", tempfile.path, output_file)
tempfile.unlink
else
sleep(60)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment