#!/bin/sh 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}') path="$HOME/Pictures/screenshots/$(date +%Y.%m.%d_%H:%M.%S).png" 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}" $path && xclip -selection clipboard -t image/png $path && paplay /usr/share/sounds/freedesktop/stereo/camera-shutter.oga notify-send -i $path "Screenshot " "Screenshot captured\nand copied to clipboard!" fi fi fi fi done exit 1