Last active
October 1, 2025 20:43
-
-
Save ariel-frischer/b376c95955d6c288b3191574c946f435 to your computer and use it in GitHub Desktop.
Wayland Screen Recording Toggle Script
This file contains hidden or 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 | |
| # ============================================================================ | |
| # Wayland Screen Recording Toggle Script | |
| # ============================================================================ | |
| # | |
| # Description: | |
| # Toggle screen recording on/off with region selection for Wayland compositors | |
| # (Hyprland, Sway, etc.). First press starts recording, second press stops it. | |
| # | |
| # Dependencies: | |
| # - wl-screenrec: High-performance Wayland screen recorder | |
| # - slurp: Region selection tool for Wayland | |
| # - notify-send: Desktop notifications (libnotify) | |
| # | |
| # Installation (Arch Linux): | |
| # paru -S wl-screenrec slurp libnotify | |
| # | |
| # Usage: | |
| # ./toggle-recording.sh | |
| # | |
| # Keybinding Example (Hyprland): | |
| # Add to ~/.config/hypr/keybindings.conf: | |
| # bind = $mainMod, R, exec, ~/.local/share/bin/toggle-recording.sh | |
| # | |
| # Output: | |
| # Videos saved to: ~/Videos/recordings/recording-YYYY-MM-DD-HH-MM-SS.mp4 | |
| # | |
| # Platform Support: | |
| # - Linux: Full support (Wayland compositors only) | |
| # - macOS: Not supported (Wayland is Linux-only) | |
| # | |
| # Notes: | |
| # - Press once to start recording (select region with mouse) | |
| # - Press again to stop recording | |
| # - Notifications show recording status and saved filename | |
| # ============================================================================ | |
| # Configuration | |
| RECORDINGS_DIR="$HOME/Videos/recordings" | |
| FRAMERATE=60 # Twitter max is 60fps, adjust if needed | |
| if pgrep -x "wl-screenrec" > /dev/null; then | |
| # Stop recording | |
| pkill -INT -x wl-screenrec | |
| # Get the most recent recording file | |
| latest_file=$(find "$RECORDINGS_DIR" -name "recording-*.mp4" -type f -printf '%T@ %p\n' 2>/dev/null | sort -rn | head -1 | cut -d' ' -f2-) | |
| if [ -n "$latest_file" ]; then | |
| filename=$(basename "$latest_file") | |
| notify-send "Recording Stopped" "$filename" | |
| else | |
| notify-send "Recording Stopped" "Video saved to $RECORDINGS_DIR/" | |
| fi | |
| else | |
| # Start recording | |
| mkdir -p "$RECORDINGS_DIR" | |
| filename="recording-$(date +'%Y-%m-%d-%H-%M-%S').mp4" | |
| notify-send "Recording Started" "Select area to record" | |
| wl-screenrec -g "$(slurp)" --max-fps "$FRAMERATE" -f "$RECORDINGS_DIR/$filename" | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment