Automatically shut down screenrecorder

About writing shell scripts and making the most of your shell
Forum rules
Topics in this forum are automatically closed 6 months after creation.
Locked
Lexdale

Automatically shut down screenrecorder

Post by Lexdale »

Hi guys

I'm using Kazam for screen recording and I want to shutdown the screen recorder after a certain time.
I've written a bash script but unfortunately it seems to destroy the video that kazam is working on.

bash script so far:

Code: Select all

#!/bin/bash

program=$1
hour=$2
minutes=$3
seconds=$4

hourSEC=$((hour*60*60))     #convert to seconds
minutesSEC=$((minutes*60))  #convert to seconds

echo ""
echo "Hours in sec" : "$hourSEC
echo "Minutes in sec: "$minutesSEC
echo "Seconds          :"$seconds
echo ""

total=$((hourSEC+minutesSEC+seconds)) 
sleep $total
pkill $1
echo "Done."
echo ""
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
User avatar
Flemur
Level 20
Level 20
Posts: 10096
Joined: Mon Aug 20, 2012 9:41 pm
Location: Potemkin Village

Re: Automatically shut down screenrecorder

Post by Flemur »

pkill $1
Just a guess, but you might need to do something like

Code: Select all

pkill -SIGSTOP  $1
so $1 exits 'gracefully'.

I'm not sure if it's SIGSTOP or what:
"pkill -SIGINT mousepad" ---> mousepad exited. (I think this is like Ctrl-C, perhaps not what you want)
"pkill -SIGSTOP mousepad" ---> mousepad stopped reacting, window still visible.

https://bash.cyberciti.biz/guide/Sendin ... _Processes

Edit:
If you're expirementing, sigstop can change how it reacts later.
$ pkill -SIGSTOP mousepad --> hung
$ pkill -SIGINT mousepad --> still hung, tho would be gone if hadn't done the sigstop first.
$ pkill -KILL mousepad --> gone.
Please edit your original post title to include [SOLVED] if/when it is solved!
Your data and OS are backed up....right?
Lexdale

Re: Automatically shut down screenrecorder

Post by Lexdale »

Flemur:

I've tried with pkill -SIGSTOP kazam
it just gets hung.
Then I tried pkill -SIGINT kazam ,but nothing happened
Then I tried pkill -KILL kazam ,totally kills the program, but the screen-recording movie is still broken into these files:

kazam_n78hah7e.movie
kazam_n78hah7e.movie.mux

Any more ideas? I've tried to look for kazam terminal commands but without any luck.
Lexdale

Re: Automatically shut down screenrecorder

Post by Lexdale »

I've solved it, but not the best way I suppose:

Code: Select all

#!/bin/bash

hour=$1
minutes=$2
seconds=$3

hourSEC=$((hour*60*60))     #convert to seconds
minutesSEC=$((minutes*60))  #convert to seconds

echo ""
echo "Hours in seconds   : "$hourSEC
echo "Minutes in seconds : "$minutesSEC
echo "Seconds            : "$seconds
echo ""

total=$((hourSEC+minutesSEC+seconds)) 
echo "Total time: "$total

echo "Put mouse in position and press enter to read it's coordinates"
read coordinates1

#-----------------------------------------------Read 1st coordinates
x1=$(xdotool getmouselocation |awk '{print $1}')
X1=$(   echo ${x1:2}   )
y1=$(xdotool getmouselocation |awk '{print $2}')
Y1=$(   echo ${y1:2}   )
echo "X1 OK: "$X1
echo "Y1 OK: "$Y1
#-----------------------------------------------END 1st coordinates

echo "Wating H:$hours , M:$minutes , S:$seconds for sending commands..."
sleep $total

xdotool mousemove $X1 $Y1 click 3
xdotool key Up Return

echo "Done."
echo ""
a better solution would be great without having to use xdotool/coordinates
Locked

Return to “Scripts & Bash”