Enhancement : small script to detect when a video is playing, NOT on fullscreen
Closed this issue · 0 comments
Hello,
Just to share a small enhancement of the script, a small script which detect when a video is playing on the active windows. It need xdotool. In fact, it detect not directly the video but if the active window run a process producing an audio output. Like most of videos come with sound, it works. If the program is running on the background, not on the active windows, as a music player working on the background, it don't stop the idle screen. It is designed for Lubuntu/Ubuntu 20.04, using pulse audio.
Just add this fonction to the loop of the lightsOn script (here I have disabled checkFullscreen) :
while true
do
checkDelayProgs
checkAudioProcessRunning
sleep $delay
done
And add this function :
checkAudioProcessRunning()
{
W=$(xprop -id $(xdotool getactivewindow) |awk '/_NET_WM_PID/ {print $3}')
S=$(pacmd list-sink-inputs | awk -F "=|:" '/application.process.id/||/state/ {gsub(""","");print $2}' ORS=' ')
R=$(echo $S | awk '{for (i=1;i<NF;i++) if (
if grep -q $W <<< $R; then
#echo "An audio process is running on active windows"
delayScreensaver
else
:
#echo "No audio process is running or not on active windows"
fi
}
W check the process id of the active window, S list the processes which have an audio output to pulse audio, extracting the application.process.id field (process id) and the state field (CORKED or RUNNING), R select the process id of the actually running audio processes. If the process id of the active window is one of these (if W if contain in R), that means than the active window is running an audio process (like a video, or a podcast, or a music file...).
Hope it will help those who don't want to be limited at the fullscreen checking.