initial commit
This commit is contained in:
74
scannerbutton.sh
Normal file
74
scannerbutton.sh
Normal file
@@ -0,0 +1,74 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Buttons:
|
||||
# b0: E-mail
|
||||
# b1: Copy
|
||||
# b2: Scan
|
||||
|
||||
echo $SCANBD_ACTION
|
||||
|
||||
# daemon's name
|
||||
#DAEMON=scanbd
|
||||
|
||||
# securely create temporary file to avoid race condition attacks
|
||||
TMPFILE=`mktemp /tmp/$DAEMON.XXXXXX`
|
||||
|
||||
# lock file
|
||||
LOCKFILE="/tmp/$DAEMON.lock"
|
||||
|
||||
# device name
|
||||
#DEVICE="$2"
|
||||
|
||||
# destination of the final image file (modify to match your setup)
|
||||
DESTINATION="media/miniretek/scanner/scan-`date +%F-%H%M`.png"
|
||||
|
||||
# remove temporary file on abort
|
||||
trap 'rm -f $TMPFILE' 0 1 15
|
||||
|
||||
# function: create lock file with scanbuttond's PID
|
||||
mk_lock() {
|
||||
pidof $DAEMON > $LOCKFILE
|
||||
}
|
||||
|
||||
# function: remove temporary and lock files
|
||||
clean_up () {
|
||||
test -e $LOCKFILE && rm -f $LOCKFILE
|
||||
rm -f $TMPFILE
|
||||
}
|
||||
|
||||
# function: check if lock file exists and print an error message with zenity (if it's installed)
|
||||
chk_lock() {
|
||||
if [ -e $LOCKFILE ]; then
|
||||
if [ -x /usr/bin/zenity ]; then
|
||||
zenity --display :0.0 --title="Scanbuttond" --error
|
||||
--text="Another scanning operation is currently in progress."
|
||||
fi
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# function: the actual scan command (modify to match your setup)
|
||||
scan() {
|
||||
#scanimage --device-name "$DEVICE" --mode Color --resolution 300 --depth 8 -x 215 -y 297 > $TMPFILE
|
||||
scanimage -x 210 -y 297 --format=png --resolution 150 > $TMPFILE
|
||||
}
|
||||
|
||||
case $SCANBD_ACTION in
|
||||
"b0")
|
||||
# button 1 (scan): scan the picture & save it as $DESTINATION
|
||||
#chk_lock; mk_lock; scan; convert $TMPFILE -quality 85 -quiet $DESTINATION; clean_up
|
||||
echo "email button pressed"
|
||||
;;
|
||||
"b1")
|
||||
# button 2 (copy): scan the picture, convert it to postscript and print it
|
||||
#chk_lock; mk_lock; scan; convert $TMPFILE ps:- | lpr; clean_up
|
||||
echo "copy button pressed"
|
||||
;;
|
||||
"b2")
|
||||
# button 3 (mail): scan the picture, save it as $DESTINATION and send it as an e-mail
|
||||
# attachment with Evolution
|
||||
# chk_lock; mk_lock; scan; convert $TMPFILE -quality 85 -quiet $DESTINATION
|
||||
# evolution --display=:0.0 "mailto:?attach=$DESTINATION"; clean_up
|
||||
echo "scan button pressed"
|
||||
;;
|
||||
esac
|
||||
Reference in New Issue
Block a user