initial commit
This commit is contained in:
68
buttonpressed.sh
Normal file
68
buttonpressed.sh
Normal file
@@ -0,0 +1,68 @@
|
||||
#!/bin/sh
|
||||
|
||||
# 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="/home/manolis/Desktop/scanned_image.jpg"
|
||||
|
||||
# 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
|
||||
}
|
||||
|
||||
case $1 in
|
||||
1)
|
||||
# button 1 (scan): scan the picture & save it as $DESTINATION
|
||||
chk_lock; mk_lock; scan; convert $TMPFILE -quality 85 -quiet $DESTINATION; clean_up
|
||||
;;
|
||||
2)
|
||||
# button 2 (copy): scan the picture, convert it to postscript and print it
|
||||
chk_lock; mk_lock; scan; convert $TMPFILE ps:- | lpr; clean_up
|
||||
;;
|
||||
3)
|
||||
# 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
|
||||
;;
|
||||
4)
|
||||
# button 4 (web): unconfigured
|
||||
echo "button 4 has been pressed on $2"
|
||||
;;
|
||||
esac
|
||||
Reference in New Issue
Block a user