Skip to content

Instantly share code, notes, and snippets.

@jD91mZM2
Forked from naelstrof/monitorshot2.sh
Last active May 10, 2020 13:25
Show Gist options
  • Save jD91mZM2/99cfe5e74e34a08f4b0854c82f9bc0b3 to your computer and use it in GitHub Desktop.
Save jD91mZM2/99cfe5e74e34a08f4b0854c82f9bc0b3 to your computer and use it in GitHub Desktop.
Just screenshots the monitor that the mouse is on.
monitors="$(xrandr | grep -o '[0-9]*x[0-9]*[+-][0-9]*[+-][0-9]*')"
# Get the location of the mouse
eval "$(xdotool getmouselocation --shell --prefix mouse_)"
while read -r line; do
if [[ "$line" =~ ([0-9]+)x([0-9]+)([+-][0-9]+)([+-][0-9]+) ]]; then
specs="${BASH_REMATCH[0]}"
width="${BASH_REMATCH[1]}"
height="${BASH_REMATCH[2]}"
x="${BASH_REMATCH[3]}"
y="${BASH_REMATCH[4]}"
echo "$width * $height + $offset_x + $offset_y"
if (( $mouse_X >= $x )) && (( $mouse_X <= $x+$width )) \
&& (( $mouse_Y >= $y )) && (( $mouse_Y <= $y+$height )); then
import -window root -crop "$specs" /tmp/screenshot.png
break
fi
fi
done < <(xrandr)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment