Created
May 30, 2023 00:36
-
-
Save rekyuu/a8b91826cf8e01b1ff626a2694176954 to your computer and use it in GitHub Desktop.
screenshot-grim.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
function get-sway-window-id() { | |
swaymsg -t get_tree | jq ".. | select(.type?) | select(.pid==$1).id" | |
} | |
function slurp-custom() { | |
slurp -b "#00000075" -c "#FF0000FF" | |
} | |
filename=$(date "+%Y-%m-%d_%H-%M-%S-%3N") | |
foldername=$(date "+%Y-%m") | |
destination_folder=~/Screenshots/$foldername | |
output="$destination_folder/$filename" | |
mkdir -p "$destination_folder" | |
case $1 in | |
all) # prtscr | |
grim "$output.png" | |
;; | |
window) # alt + prtscr | |
window=$(swaymsg -t get_tree | jq '.. | select(.type?) | select(.focused==true)') | |
pos_x=$(echo "$window" | jq ".rect.x") | |
pos_y=$(echo "$window" | jq ".rect.y") | |
width=$(echo "$window" | jq ".rect.width") | |
height=$(echo "$window" | jq ".rect.height") | |
grim -g "${pos_x},${pos_y} ${width}x${height}" "$output.png" | |
;; | |
selection) # shift + prtscr | |
grim -t ppm - | feh - & | |
FEH_PID=$! | |
swaymsg "for_window [pid=$FEH_PID] fullscreen enable global" | |
while [ -z "$(get-sway-window-id $FEH_PID)" ]; do | |
sleep 0.1 | |
done | |
grim -g "$(slurp-custom)" "$output.png" | |
kill "$FEH_PID" | |
;; | |
esac | |
if [[ -f "$output.png" ]]; then | |
wl-copy < "$output.png" | |
notify-send "Image copied to clipboard." | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment