Screen Record
This script record the screen with the wf-recorder
tool, it can be the hole screen or a specific area of it.
The script is going to store the video in /tmp/screencast.mp4
, this script only store one video, personally I think that have more than one record is a mess, more if you only wants to share a quick screencast to telegram, irc, cinny or even to share it through 0x0.st
.
Description and main variables:
1# Created By: Javier Pacheco - javier@jpacheco.xyz
2# Created On: 29/03/24
3# Project: Screen recorder in wayland
4# Dependencies: wf-recorder wl-copy and a launcher like dmenu, fuzzel, etc.
5
6SOUND_CARD=$(pactl list sources | awk '/Name/ && /.monitor/ {print $2}')
Recording functions:
Those functions have enable the sound recording, so if you have some music, video, etc running it will record the sound but not the mic.
screencast:
This option is going to record a specific area of the screen.
This area is going to be specified by slurp
.
1screencast() {
2 wf-recorder --audio=$SOUND_CARD -f /tmp/screencast.mp4
3}
area:
This option is going to record a specific area of the screen.
This area is going to be specified by slurp
.
1area() {
2 wf-recorder --audio=$SOUND_CARD -g "$(slurp)" -f /tmp/screencast.mp4
3}
Main functions:
These functions are tools that ensures this script works correctly. For example if all ready have a existing file recorded, it will removed to record a new one, because this script only will create one video always, and also have a function to kill the process when it finished.
check internet connection:
1check_connection() {
2 ping -c 1 google.com 1> /dev/null 2>&1
3}
share:
This option is going to upload the video to 0x0.st
and copy the url to the clipboard using wc-copy
.
1share() {
2 notify-send "uploading.." "video is upoading to 0x0.st"
3 curl -F "file=@/tmp/screencast.mp4" https://0x0.st | wl-copy && notify-send "Video stored in 0x0.st"
4}
Kill existing process:
1kill_proc(){
2 pkill --signal SIGINT wf-recorder
3 if [ $? -eq 0 ];
4 then
5 notify-send "Video stored" "Video was stored in /tmp/screencast.mp4"
6 pkill --signal SIGINT wf-recorder
7 exit 0
8 fi
9}
Remove existing video:
1remove_vid() {
2 [ -f /tmp/screencast.mp4 ] && rm /tmp/screencast.mp4
3}
Sequence:
This is were the scripts actually starts, first of all look if the script is already running, if not then ask for a recording option:
1kill_proc
2
3OPT=$(printf "screencast\narea\nshare\nquit" | fuzzel --dmenu -p 'Select an option: ' )
4case $OPT in
5 'screencast')
6 sleep 1
7 remove_vid
8 sleep 1
9 screencast;;
10 'area')
11 sleep 1
12 remove_vid
13 sleep 1
14 area;;
15 'share')
16 check_connection && share || notify-send "Error" "check your internet connection" ;;
17 *|quit) exit 0;;
18esac
The whole code.
1# Created By: Javier Pacheco - javier@jpacheco.xyz
2# Created On: 29/03/24
3# Project: Screen recorder in wayland
4# Dependencies: wf-recorder wl-copy and a launcher like dmenu, fuzzel, etc.
5
6SOUND_CARD=$(pactl list sources | awk '/Name/ && /.monitor/ {print $2}')
7
8screencast() {
9 wf-recorder --audio=$SOUND_CARD -f /tmp/screencast.mp4
10}
11
12area() {
13 wf-recorder --audio=$SOUND_CARD -g "$(slurp)" -f /tmp/screencast.mp4
14}
15
16check_connection() {
17 ping -c 1 google.com 1> /dev/null 2>&1
18}
19
20share() {
21 notify-send "uploading.." "video is upoading to 0x0.st"
22 curl -F "file=@/tmp/screencast.mp4" https://0x0.st | wl-copy && notify-send "Video stored in 0x0.st"
23}
24
25kill_proc(){
26 pkill --signal SIGINT wf-recorder
27 if [ $? -eq 0 ];
28 then
29 notify-send "Video stored" "Video was stored in /tmp/screencast.mp4"
30 pkill --signal SIGINT wf-recorder
31 exit 0
32 fi
33}
34
35remove_vid() {
36 [ -f /tmp/screencast.mp4 ] && rm /tmp/screencast.mp4
37}
38
39kill_proc
40
41OPT=$(printf "screencast\narea\nshare\nquit" | fuzzel --dmenu -p 'Select an option: ' )
42case $OPT in
43 'screencast')
44 sleep 1
45 remove_vid
46 sleep 1
47 screencast;;
48 'area')
49 sleep 1
50 remove_vid
51 sleep 1
52 area;;
53 'share')
54 check_connection && share || notify-send "Error" "check your internet connection" ;;
55 *|quit) exit 0;;
56esac