Dotfiles/desktopenvs/hyprdrive/scripts/screenrec.sh

40 lines
1.3 KiB
Bash
Executable File

#!/bin/bash
# screenrec.sh — toggle screen recording via wf-recorder.
# Press the bound key once to start (region picked via slurp): a
# "Stop Recording" button appears on the notification and the script blocks
# on it. Either clicking that button, or pressing the same keybind again,
# ends the recording.
endrec () {
killall -s SIGINT wf-recorder
# beacon (the notif daemon) has no dunstctl; close the "recording started"
# card via the freedesktop CloseNotification method instead.
[ -n "$nid" ] && gdbus call --session --dest org.freedesktop.Notifications \
--object-path /org/freedesktop/Notifications \
--method org.freedesktop.Notifications.CloseNotification "$nid" >/dev/null 2>&1
notify-send "recording ended - output to $outfile"
}
mkdir -p ~/Videos
statecon=$( pidof wf-recorder )
outfile="$HOME/Videos/$(date +'%Y%m%d%H%M%S').mp4"
nid=""
if [ -z "$statecon" ]; then
wf-recorder -g "$(slurp)" -f "$outfile" &
# --id-fd keeps the notification id off stdout so -A's chosen action
# (the only thing we read back) isn't mixed in with it.
nidfile=$(mktemp)
action=$(notify-send -u critical -t 0 --id-fd=3 \
-A "stop=Stop Recording" \
"recording started" "output: $outfile" 3>"$nidfile")
nid=$(<"$nidfile")
rm -f "$nidfile"
[ "$action" == "stop" ] && endrec
else
endrec
fi