neodotfiles/new-config/.config/rofi/scripts/rofi_scrot
Clay Gomera f7fa1a14fe updated
2023-03-31 09:35:01 -04:00

115 lines
2.3 KiB
Bash
Executable file

#!/usr/bin/env bash
# Screenshot directory
screenshot_directory="$HOME/Pictures/Screenshots"
mkdir -p "$screenshot_directory"
countdown() {
notify-send "Screenshot" "Executing in 3 seconds" -t 1000
sleep 1
notify-send "Screenshot" "Executing in 2 seconds" -t 1000
sleep 1
notify-send "Screenshot" "Executing in 1 seconds" -t 1000
sleep 2
}
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() {
countdown
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 rofi
check_deps wf-recorder
if [[ $1 == '--help' ]] || [[ $1 = '-h' ]]
then
echo ### rofi-screenshot
echo USAGE: rofi-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) | rofi -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