File indexing completed on 2024-05-12 08:34:05

0001 #!/bin/bash
0002 
0003 # Skanlite D-Bus example script
0004 
0005 # this script listens for D-Bus buttonPressed signal from Skanlite
0006 # checks which button is pressed (default: 'Button 0') and its pressed state
0007 # then sends Skanlite 'scan' command via D-Bus
0008 
0009 # WARNING: buttonPressed signal might work unstable as it's driver dependant
0010 # WARNING: for example my HP 4370 stop sending hw btn events just after first scan
0011 
0012 interface=org.kde.skanlite
0013 sender=org.kde.skanlite
0014 member=buttonPressed
0015 command=scan
0016 
0017 # listen for buttonPressed D-Bus events,
0018 # each time we enter the loop, we just got an event
0019 # so handle the event, e.g. by checking button name and its state.
0020 
0021 dbus-monitor --profile "type='signal',sender='$sender',interface='$interface',member='$member'" --monitor |
0022 while read -r line; do
0023 
0024 # uncomment the line below to output to console all incoming buttonPressed data
0025 # this may be useful to detect proper button names
0026 
0027 # printf "Received line: $line\n"
0028 
0029   if [[ $line == *"button 0"* ]]; then
0030    read -r line;
0031    if [[ $line == *"Scanner button 0"* ]]; then
0032     read -r line;
0033      if [[ $line == *"boolean true"* ]]; then
0034       # printf "\nButton pressed. Performing scan.\n"
0035       dbus-send --session --dest=$interface --type=method_call  / $interface.$command
0036      fi
0037    fi
0038   fi
0039 done