Adds new screenshot script
This commit is contained in:
parent
c5b55c5459
commit
064740cbf4
3 changed files with 63 additions and 150 deletions
|
|
@ -84,8 +84,8 @@ bindm = $mainMod SHIFT, mouse:273, resizewindow
|
||||||
|
|
||||||
# Stuff
|
# Stuff
|
||||||
bind = $mainMod, N, exec, $scriptsDir/LockScreen.sh # screen lock
|
bind = $mainMod, N, exec, $scriptsDir/LockScreen.sh # screen lock
|
||||||
bind = , Print, exec, $scriptsDir/ScreenShot.sh --area # screenshot (area)
|
bind = , Print, exec, $scriptsDir/screenshot.sh area # screenshot (area)
|
||||||
bind = , F12, exec, $scriptsDir/ScreenShot.sh --active # screenshot (active window only)
|
bind = , F12, exec, $scriptsDir/screenshot.sh active # screenshot (active window only)
|
||||||
|
|
||||||
bind = $mainMod SHIFT, N, exec, $scriptsDir/anyrun/Toolkit.sh # swayNC notification panel
|
bind = $mainMod SHIFT, N, exec, $scriptsDir/anyrun/Toolkit.sh # swayNC notification panel
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,148 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
# /* ---- 💫 https://github.com/JaKooLit 💫 ---- */ ##
|
|
||||||
# Screenshots scripts
|
|
||||||
|
|
||||||
time=$(date "+%d-%b_%H-%M-%S")
|
|
||||||
dir="$(xdg-user-dir)/Pictures/Screenshots"
|
|
||||||
file="Screenshot_${time}_${RANDOM}.png"
|
|
||||||
|
|
||||||
active_window_class=$(hyprctl -j activewindow | jq -r '(.class)')
|
|
||||||
active_window_file="Screenshot_${time}_${active_window_class}.png"
|
|
||||||
active_window_path="${dir}/${active_window_file}"
|
|
||||||
|
|
||||||
notify_cmd_base="notify-send -i "shoot" -t 10000 -A action1=Open -A action2=Delete -h string:x-canonical-private-synchronous:shot-notify"
|
|
||||||
#notify_swappy="notify-send -h string:x-canonical-private-synchronous:shot-notify -u low -i ${iDIR}/picture.png"
|
|
||||||
notify_cmd_shot="${notify_cmd_base}"
|
|
||||||
notify_cmd_shot_win="${notify_cmd_base}"
|
|
||||||
|
|
||||||
# notify and view screenshot
|
|
||||||
notify_view() {
|
|
||||||
if [[ "$1" == "active" ]]; then
|
|
||||||
if [[ -e "${active_window_path}" ]]; then
|
|
||||||
resp=$(timeout 5 ${notify_cmd_shot_win} " Screenshot of:" " ${active_window_class} Saved.")
|
|
||||||
case "$resp" in
|
|
||||||
action1)
|
|
||||||
xdg-open "${active_window_path}" &
|
|
||||||
;;
|
|
||||||
action2)
|
|
||||||
rm "${active_window_path}" &
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
else
|
|
||||||
${notify_cmd_shot} " Screenshot of:" " ${active_window_class} NOT Saved."
|
|
||||||
"${sDIR}/Sounds.sh" --error
|
|
||||||
fi
|
|
||||||
|
|
||||||
elif [[ "$1" == "swappy" ]]; then
|
|
||||||
resp=$(${notify_cmd_shot} " Screenshot:" " Captured by Swappy")
|
|
||||||
case "$resp" in
|
|
||||||
action1)
|
|
||||||
swappy -f - <"$tmpfile"
|
|
||||||
;;
|
|
||||||
action2)
|
|
||||||
rm "$tmpfile"
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
else
|
|
||||||
local check_file="${dir}/${file}"
|
|
||||||
if [[ -e "$check_file" ]]; then
|
|
||||||
resp=$(timeout 5 ${notify_cmd_shot} " Screenshot" " Saved")
|
|
||||||
case "$resp" in
|
|
||||||
action1)
|
|
||||||
xdg-open "${check_file}" &
|
|
||||||
;;
|
|
||||||
action2)
|
|
||||||
rm "${check_file}" &
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
else
|
|
||||||
${notify_cmd_shot} " Screenshot" " NOT Saved"
|
|
||||||
"${sDIR}/Sounds.sh" --error
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# countdown
|
|
||||||
countdown() {
|
|
||||||
for sec in $(seq $1 -1 1); do
|
|
||||||
notify-send -h string:x-canonical-private-synchronous:shot-notify -t 1000 -i "$iDIR"/timer.png " Taking shot" " in: $sec secs"
|
|
||||||
sleep 1
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
# take shots
|
|
||||||
shotnow() {
|
|
||||||
cd ${dir} && grim - | tee "$file" | wl-copy
|
|
||||||
sleep 2
|
|
||||||
notify_view
|
|
||||||
}
|
|
||||||
|
|
||||||
shot5() {
|
|
||||||
countdown '5'
|
|
||||||
sleep 1 && cd ${dir} && grim - | tee "$file" | wl-copy
|
|
||||||
sleep 1
|
|
||||||
notify_view
|
|
||||||
}
|
|
||||||
|
|
||||||
shot10() {
|
|
||||||
countdown '10'
|
|
||||||
sleep 1 && cd ${dir} && grim - | tee "$file" | wl-copy
|
|
||||||
notify_view
|
|
||||||
}
|
|
||||||
|
|
||||||
shotwin() {
|
|
||||||
w_pos=$(hyprctl activewindow | grep 'at:' | cut -d':' -f2 | tr -d ' ' | tail -n1)
|
|
||||||
w_size=$(hyprctl activewindow | grep 'size:' | cut -d':' -f2 | tr -d ' ' | tail -n1 | sed s/,/x/g)
|
|
||||||
cd ${dir} && grim -g "$w_pos $w_size" - | tee "$file" | wl-copy
|
|
||||||
notify_view
|
|
||||||
}
|
|
||||||
|
|
||||||
shotarea() {
|
|
||||||
tmpfile=$(mktemp)
|
|
||||||
grim -g "$(slurp)" - >"$tmpfile"
|
|
||||||
if [[ -s "$tmpfile" ]]; then
|
|
||||||
wl-copy <"$tmpfile"
|
|
||||||
mv "$tmpfile" "$dir/$file"
|
|
||||||
fi
|
|
||||||
notify_view
|
|
||||||
}
|
|
||||||
|
|
||||||
shotactive() {
|
|
||||||
active_window_class=$(hyprctl -j activewindow | jq -r '(.class)')
|
|
||||||
active_window_file="Screenshot_${time}_${active_window_class}.png"
|
|
||||||
active_window_path="${dir}/${active_window_file}"
|
|
||||||
|
|
||||||
hyprctl -j activewindow | jq -r '"\(.at[0]),\(.at[1]) \(.size[0])x\(.size[1])"' | grim -g - "${active_window_path}"
|
|
||||||
sleep 1
|
|
||||||
notify_view "active"
|
|
||||||
}
|
|
||||||
|
|
||||||
shotswappy() {
|
|
||||||
tmpfile=$(mktemp)
|
|
||||||
grim -g "$(slurp)" - >"$tmpfile" && notify_view "swappy"
|
|
||||||
}
|
|
||||||
|
|
||||||
if [[ ! -d "$dir" ]]; then
|
|
||||||
mkdir -p "$dir"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ "$1" == "--now" ]]; then
|
|
||||||
shotnow
|
|
||||||
elif [[ "$1" == "--in5" ]]; then
|
|
||||||
shot5
|
|
||||||
elif [[ "$1" == "--in10" ]]; then
|
|
||||||
shot10
|
|
||||||
elif [[ "$1" == "--win" ]]; then
|
|
||||||
shotwin
|
|
||||||
elif [[ "$1" == "--area" ]]; then
|
|
||||||
shotarea
|
|
||||||
elif [[ "$1" == "--active" ]]; then
|
|
||||||
shotactive
|
|
||||||
elif [[ "$1" == "--swappy" ]]; then
|
|
||||||
shotswappy
|
|
||||||
else
|
|
||||||
echo -e "Available Options : --now --in5 --in10 --win --area --active --swappy"
|
|
||||||
fi
|
|
||||||
|
|
||||||
exit 0
|
|
||||||
61
.config/scripts/screenshot.sh
Executable file
61
.config/scripts/screenshot.sh
Executable file
|
|
@ -0,0 +1,61 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
NOTIFY_CMD="notify-send -i "shoot" -t 10000 -A open=Open -A delete=Delete *click*"
|
||||||
|
|
||||||
|
TARGET_DIRECTORY="$(xdg-user-dir)/Pictures/Screenshots"
|
||||||
|
|
||||||
|
SOURCE="${1:-area}"
|
||||||
|
TEMP_FILE="/tmp/screenshot.png"
|
||||||
|
|
||||||
|
getGrimArea() {
|
||||||
|
case $SOURCE in
|
||||||
|
area)
|
||||||
|
workspaces=$(hyprctl -j monitors | jq -r 'map(".workspace.id == \(.activeWorkspace.id)") | join(" or ")')
|
||||||
|
hyprctl -j clients |
|
||||||
|
jq -r ".[] | select($workspaces) | \"\(.at[0]),\(.at[1]) \(.size[0])x\(.size[1]) \(.class)\"" |
|
||||||
|
slurp -b "#11111177" -c "#1090ffff" -d -F mono
|
||||||
|
;;
|
||||||
|
active)
|
||||||
|
hyprctl -j activewindow | jq -r '"\(.at[0]),\(.at[1]) \(.size[0])x\(.size[1])"'
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
return $?
|
||||||
|
}
|
||||||
|
|
||||||
|
targetFolder=""
|
||||||
|
if [[ $SOURCE == "active" ]]; then
|
||||||
|
targetFolder="/$(hyprctl -j activewindow | jq -r '(.class)')"
|
||||||
|
fi
|
||||||
|
|
||||||
|
targetPath="$TARGET_DIRECTORY$targetFolder"
|
||||||
|
mkdir -m 0744 -p "$targetPath"
|
||||||
|
|
||||||
|
targetPath="$targetPath/$(date "+%d-%b_%H-%M-%S").png"
|
||||||
|
|
||||||
|
area="$(getGrimArea)"
|
||||||
|
if [[ $? != 0 ]]; then
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
if [[ "$area" == 'invalid geometry' ]]; then
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
echo "$area"
|
||||||
|
|
||||||
|
sleep 0.1
|
||||||
|
grim -g "$area" "$targetPath"
|
||||||
|
|
||||||
|
wl-copy <"$targetPath"
|
||||||
|
|
||||||
|
response=$(
|
||||||
|
${NOTIFY_CMD} "Took screenshot"
|
||||||
|
)
|
||||||
|
echo "Responded with '$response'"
|
||||||
|
|
||||||
|
case "$response" in
|
||||||
|
delete)
|
||||||
|
rm "$targetPath"
|
||||||
|
;;
|
||||||
|
open)
|
||||||
|
hyprctl dispatch exec xdg-open "$targetPath" &
|
||||||
|
;;
|
||||||
|
esac
|
||||||
Loading…
Add table
Add a link
Reference in a new issue