I am having difficulty with a bash script on my Linux Box. It is supposed to define a square area on my mainscreen (which it does) and then wait for the mouse to click within that square. The script launches, then waits, but as soon as the mouse enters the area of defined screenspace, the script reacts instead of waiting for a mouse click in the square. Can anyone help?
Script:
Code: Select all
#!/bin/bash
# Define the coordinates of the clickable box
box_x=780
box_y=385
box_width=300
box_height=260
# Function to check if the mouse is inside the box
mouse_inside_box() {
mouse_x=$(xdotool getmouselocation --shell | grep 'X' | awk -F'=' '{print $2}')
mouse_y=$(xdotool getmouselocation --shell | grep 'Y' | awk -F'=' '{print $2}')
if [ "$mouse_x" -ge "$box_x" ] && [ "$mouse_x" -le "$((box_x + box_width))" ] && \
[ "$mouse_y" -ge "$box_y" ] && [ "$mouse_y" -le "$((box_y + box_height))" ]; then
return 0 # Mouse is inside the box
else
return 1 # Mouse is outside the box
fi
}
# Wait for a mouse click event within the specified box
while true; do
if mouse_inside_box && xdotool click 1; then
# Play a beep sound at max volume
paplay /usr/share/sounds/freedesktop/stereo/complete.oga
# Run your script after a mouse click
pkill -f "conky -c /home/logansfury/.conky/Biohazzard/conkyrc"
break # Exit the loop after the script is executed
fi
sleep 0.1 # Adjust the sleep duration as needed
done
Logan