neodotfiles/new-config/.config/wofi/scripts/wofi_scrot
Clay Gomera cb20ec8814 updated
2023-02-21 20:02:06 -04:00

113 lines
2.3 KiB
Bash
Executable file

#!/usr/bin/env bash
# Screenshot directory
screenshot_directory="$HOME/Pictures/Screenshots"
countdown() {
notify-send "Screenshot" "Recording in 3 seconds" -t 1000
sleep 1
notify-send "Screenshot" "Recording in 2 seconds" -t 1000
sleep 1
notify-send "Screenshot" "Recording in 1 seconds" -t 1000
sleep 1
}
crtf() {
notify-send "Screenshot" "Select a region to capture"
dt=$(date '+%d-%m-%Y %H:%M:%S')
grim -g "$(slurp)" "$screenshot_directory/$dt.png"
notify-send "Screenshot" "Region saved to $screenshot_directory"
}
cstf() {
dt=$(date '+%d-%m-%Y %H:%M:%S')
grim "$screenshot_directory/$dt.png"
notify-send "Screenshot" "Screenshot saved to $screenshot_directory"
}
rvrtf() {
notify-send "Screenshot" "Select a region to record"
dt=$(date '+%d-%m-%Y %H:%M:%S')
wf-recorder -g "$(slurp)" rec "$screenshot_directory/$dt.mp4"
notify-send "Screenshot" "Recording saved to $screenshot_directory"
}
rvstf() {
countdown
dt=$(date '+%d-%m-%Y %H:%M:%S')
wf-recorder -f "$screenshot_directory/$dt.mp4"
notify-send "Screenshot" "Recording saved to $screenshot_directory"
}
get_options() {
echo " Capture Region"
echo " Capture Screen"
echo " Record Region"
echo " Record Screen"
}
check_deps() {
if ! hash $1 2>/dev/null; then
echo "Error: This script requires $1"
exit 1
fi
}
main() {
# check dependencies
check_deps slurp
check_deps grim
check_deps wofi
check_deps wf-recorder
if [[ $1 == '--help' ]] || [[ $1 = '-h' ]]
then
echo ### wofi-screenshot
echo USAGE: wofi-screenshot [OPTION]
echo \(no option\)
echo " show the screenshot menu"
echo -s, --stop
echo " stop recording"
echo -h, --help
echo " this screen"
exit 1
fi
if [[ $1 = '--stop' ]] || [[ $1 = '-s' ]]
then
killall -s SIGINT wf-recorder
exit 1
fi
# Get choice from rofi
choice=$( (get_options) | wofi --dmenu -p "Screenshot" )
# If user has not picked anything, exit
if [[ -z "${choice// }" ]]; then
exit 1
fi
# run the selected command
case $choice in
' Capture Region')
crtf
;;
' Capture Screen')
cstf
;;
' Record Region')
rvrtf
;;
' Record Screen')
rvstf
;;
esac
# done
set -e
}
main $1 &
exit 0
!/bin/bash