Last active
May 25, 2024 00:07
-
-
Save raffaem/bb9c35c6aab663efd7a0400c33d248a1 to your computer and use it in GitHub Desktop.
Waybar module to record screen
This file contains 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
Left mouse button to record entire screen, right mouse button to record a region. | |
Requires [wf-recorder](https://github.com/ammen99/wf-recorder). |
This file contains 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
"custom/recording": { | |
"exec": "$XDG_CONFIG_HOME/waybar/scripts/recording.sh status", | |
"format": "{}", | |
"on-click": "$XDG_CONFIG_HOME/waybar/scripts/recording.sh toggle fullscreen", | |
"on-click-right": "$XDG_CONFIG_HOME/waybar/scripts/recording.sh toggle region", | |
"restart-interval": 1, | |
"return-type": "json", | |
"tooltip": true | |
}, |
This file contains 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
#!/usr/bin/env bash | |
# $XDG_CONFIG_HOME/waybar/scripts/recording.sh | |
pidf="$HOME/Videos/Screencasts/process.pid" | |
WF_RECORDER_OPTS="" | |
VIDEOEXT="mkv" | |
if [ "$1" == "status" ]; | |
then | |
if [ -f "$pidf" ]; | |
then | |
awk 'BEGIN{printf "{\"text\":\"\", \"tooltip\":\"Recording\\n"} | |
NR==1{printf "PID: %s\\n", $0} | |
NR==2{printf "Save to: %s\\n", $0} | |
NR==3{printf "Log to: %s\"}", $0}' "$pidf" | |
else | |
echo '{"text":"", "tooltip":"Stopped"}' | |
fi | |
exit | |
elif [ "$1" == "toggle" ]; | |
then | |
if [ -f "$pidf" ]; | |
then | |
pid=$(cat "$pidf") | |
kill -2 "$pid" | |
rm "$pidf" | |
else | |
mkdir -p "$HOME/Videos/Screencasts" | |
bf="$HOME/Videos/Screencasts/$(date +'%Y%m%dT%H%M%S')" | |
vidf="$bf.$VIDEOEXT" | |
logf="$bf.log" | |
if [ "$2" == "fullscreen" ]; then | |
wf-recorder $WF_RECORDER_OPTS -f "$vidf" 1>"$logf" 2>&1 & | |
elif [ "$2" == "region" ]; then | |
sleep 1 | |
wf-recorder $WF_RECORDER_OPTS -g "$(slurp)" -f "$vidf" 1>"$logf" 2>&1 & | |
else | |
printf "Argument %s not valid" "$2" | |
exit | |
fi | |
pid=$(jobs -p | tail -n 1) | |
printf "%d\n%s\n%s" "$pid" "$vidf" "$logf" > "$pidf" | |
disown "$pid" | |
fi | |
exit | |
else | |
printf "Argument %s not valid" "$1" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment