Last active
December 17, 2015 05:39
-
-
Save Luzifer/5559874 to your computer and use it in GitHub Desktop.
Imports an image from a twain sane scanner, converts to jpg and saves it to the desktop of the current user, then opens it with Preview.app
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
#!/bin/bash | |
targetfile="scan_$( date +"%Y-%m-%d_%H-%M-%S" ).jpg" | |
# Get image from scanner | |
scanimage --format=tiff --resolution 300 > /tmp/scan.tiff | |
# TODO: Search for correct error message (need it to be thrown by scanimage before implementing) | |
if [ $(grep -q 'cups' /tmp/scan.tiff ) ]; then | |
# Calculate size of file without error message | |
newsize=$(( $(wc -c /tmp/scan.tiff | sed "s/^[^0-9]*\([0-9]*\)[^0-9].*$/\1/") - 22 )) | |
# Remove error message | |
tail -c $newsize /tmp/scan.tiff > /tmp/scannew.tiff | |
mv /tmp/scannew.tiff /tmp/scan.tiff | |
fi | |
# Use convert to create a jpg | |
convert -quality 90 /tmp/scan.tiff "$HOME/Desktop/$targetfile" | |
# Remove tiff | |
rm /tmp/scan.tiff | |
# Open jpg in default JPG viewer (mostly preview) to be edited | |
open "$HOME/Desktop/$targetfile" |
Thanks for your hints. :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Instead of creating
$homedir
manually, why not just use$HOME
?Also, you might want to wrap stuff like
$homedir/Desktop/$targetfile
in quotes, in case the expanded string contains spaces.