Skip to content

Instantly share code, notes, and snippets.

@naelstrof
Last active June 15, 2024 20:40
Show Gist options
  • Save naelstrof/f9b74b5221cdc324c0911c89a47b8d97 to your computer and use it in GitHub Desktop.
Save naelstrof/f9b74b5221cdc324c0911c89a47b8d97 to your computer and use it in GitHub Desktop.
Just screenshots the monitor that the mouse is on.
#!/bin/bash
MONITORS=$(xrandr | grep -o '[0-9]*x[0-9]*[+-][0-9]*[+-][0-9]*')
# Get the location of the mouse
XMOUSE=$(xdotool getmouselocation | awk -F "[: ]" '{print $2}')
YMOUSE=$(xdotool getmouselocation | awk -F "[: ]" '{print $4}')
for mon in ${MONITORS}; do
# Parse the geometry of the monitor
MONW=$(echo ${mon} | awk -F "[x+]" '{print $1}')
MONH=$(echo ${mon} | awk -F "[x+]" '{print $2}')
MONX=$(echo ${mon} | awk -F "[x+]" '{print $3}')
MONY=$(echo ${mon} | awk -F "[x+]" '{print $4}')
# Use a simple collision check
if (( ${XMOUSE} >= ${MONX} )); then
if (( ${XMOUSE} <= ${MONX}+${MONW} )); then
if (( ${YMOUSE} >= ${MONY} )); then
if (( ${YMOUSE} <= ${MONY}+${MONH} )); then
# We have found our monitor!
maim -g "${MONW}x${MONH}+${MONX}+${MONY}" someplace.png
exit 0
fi
fi
fi
fi
done
echo "Oh no the mouse is in the void!"
exit 1
@naelstrof
Copy link
Author

-maim -g"${MONW}x${MONH}+${MONX}+${MONY}" someplace.png
+maim -g "${MONW}x${MONH}+${MONX}+${MONY}" someplace.png

Great script btw! Thank you

Fixed. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment