#!/bin/bash # We need to decide if we're already screen recording or not pid=$(pgrep wf-recorder) if [[ "$pid" ]]; then # Just killing the wf-recorder task frees up the rest of the script to do the rest kill -9 "$pid" else filename="/home/jose/Pictures/Screenshots/$(date '+%Y-%m-%d_%I:%M:%S%p')" # Start the screen recording in the region defined by Slurp # If you hit cancel the slurp, we need to handle that. if ! screen_region=$(slurp -b '#00000090'); then notify-send -a 'Screen Recording' 'Cancelled!' paplay $(dirname "$(realpath $0)")/sounds/ErrorSound.wav --volume 98302 exit 0 fi # Now that we've shown the area, play the screenrec sound as a trigger paplay $(dirname "$(realpath $0)")/sounds/CaptureSound.wav --volume 98302 # Finally start recording wf-recorder -g "$screen_region" -f "$filename.mkv" # Convert to MP4 - mp4 breaks if you kill-9 it, but mkv doesn't. Keep benefits of both ffmpeg -i "$filename.mkv" -codec copy "$filename.mp4" && rm "$filename.mkv" # Copy the output file to the clipboard wl-copy file://"$filename.mp4" -t text/uri-list # Now we can say the recording is done - replace the existing notif notify-send -a 'Screen Recording' 'Saved + Copied to Clipboard' # Play a little sound to go with it :) paplay $(dirname "$(realpath $0)")/sounds/TaskCompletedSound.wav --volume 98302 fi