#!/bin/sh # This is bound to Shift+PrintScreen by default, requires maim. It lets you # choose the kind of screenshot to take, including copying the image or even # highlighting an area to copy. scrotcucks on suicidewatch right now. # variables output_dir="${XDG_PICTURES_DIR:-${HOME}/Pictures}/screenshots/" output="$(date '+%y%m%d-%H%M-%S').png" xclip_cmd="xclip -sel clip -t image/png" ocr_cmd="xclip -sel clip" [ -d "$output_dir" ] || mkdir -p "$output_dir" # Number of connected monitors (first line of xrandr --listmonitors). mon_count="$(xrandr --listmonitors | awk 'NR==1{print $2}')" # Prompt for a monitor and print its maim -g geometry (WxH+X+Y), or nothing if # the picker is cancelled. pick_monitor() { monitors="$(xrandr --listmonitors | tail -n +2)" name="$(printf '%s\n' "$monitors" | awk '{print $NF}' | dmenu -i -p "Which monitor?")" || return 1 [ -z "$name" ] && return 1 printf '%s\n' "$monitors" | awk -v n="$name" '$NF==n {gsub(/\/[0-9]+/,"",$3); print $3}' } # Build the menu, only offering the monitor entries when more than one is # connected. options="a selected area current window full screen" [ "$mon_count" -gt 1 ] 2>/dev/null && options="$options selected monitor" options="$options a selected area (copy) current window (copy) full screen (copy)" [ "$mon_count" -gt 1 ] 2>/dev/null && options="$options selected monitor (copy)" options="$options copy selected image to text" lines="$(printf '%s\n' "$options" | wc -l)" case "$(printf '%s\n' "$options" | dmenu -l "$lines" -i -p "Screenshot which area?")" in "a selected area") maim -u -s "$output_dir"pic-selected-"${output}" ;; "current window") maim -B -q -d 0.2 -i "$(xdotool getactivewindow)" "$output_dir"pic-window-"${output}" ;; "full screen") maim -q -d 0.2 "$output_dir"pic-full-"${output}" ;; "selected monitor") geo="$(pick_monitor)" && [ -n "$geo" ] && maim -q -d 0.2 -g "$geo" "$output_dir"pic-monitor-"${output}" ;; "a selected area (copy)") maim -u -s | ${xclip_cmd} ;; "current window (copy)") maim -q -d 0.2 -i "$(xdotool getactivewindow)" | ${xclip_cmd} ;; "full screen (copy)") maim -q -d 0.2 | ${xclip_cmd} ;; "selected monitor (copy)") geo="$(pick_monitor)" && [ -n "$geo" ] && maim -q -d 0.2 -g "$geo" | ${xclip_cmd} ;; "copy selected image to text") tmpfile=$(mktemp /tmp/ocr-XXXXXX.png) && maim -u -s >"$tmpfile" && tesseract "$tmpfile" - -l eng | ${ocr_cmd} && rm "$tmpfile" ;; esac