#!/bin/bash function area() { maim --select --tolerance 0 "$@" && \ echo "the selected area" } function screen() { maim "$@" && \ echo "the full screen" } function current_window() { WINDOW_ID=$(xdotool getwindowfocus) && \ WINDOW_NAME=$(xdotool getwindowname "$WINDOW_ID") && \ maim --window="$WINDOW_ID" "$@" && \ echo "the current window ($WINDOW_NAME)" } function select_window() { maim --select --tolerance 999999 "$@" && \ echo "the selected window" } OPTION=$1 shift OPTION_TYPE=$(type -t "$OPTION") if [[ $OPTION_TYPE != function ]]; then >&2 echo "Must give the type of screenshot: area, screen, current_window, or select_window, but gave ${OPTION:-(nothing)} which was ${OPTION_TYPE:-undefined}" exit 1 fi SCREENSHOT_DIR=~/Screenshots if [[ ! -d $SCREENSHOT_DIR ]]; then if [[ ! -t 2 ]]; then if [[ -z $SCREENSHOT_DIR ]]; then dunstify --appname=screenshot.sh --timeout 3000 "Screenshot Failed" "Failed to take screenshot: Screenshot directory not set" else dunstify --appname=screenshot.sh --timeout 3000 "Screenshot Failed" "Failed to take screenshot: No such directory ${SCREENSHOT_DIR}" fi else >&2 echo "Must give the screenshot directory, which must exist and be a directory, but gave ${SCREENSHOT_DIR:-(nothing)}" fi exit 2 fi FILENAME=${SCREENSHOT_DIR}/Screenshot\ from\ $(date '+%Y-%m-%d %H-%M-%S').png AREA=$("$OPTION" "$@" "$FILENAME") && \ xclip -selection clipboard -t image/png < "$FILENAME" && \ dunstify --appname=screenshot.sh --timeout 3000 --raw_icon="$FILENAME" "Screenshot Captured" "Saved screenshot of $AREA to clipboard and $FILENAME" && \ "$(readlink -e "$( dirname "$(realpath -e "${BASH_SOURCE[0]}")" )")/recently_used/recently_used.py" -A screenshot.sh "$FILENAME"