I use an external monitor that has an audio output and use it for my audio system. However, if the desktop enters in sleep mode, it automatically switches to the laptop speakers.
I want to use pacmd list-sink-inputs | grep 'RUNNING'
to check every 20 seconds if sound is playing, and if so reset the idle time automatically.
Currently I use caffeine, but that disables idling completely.
How can I prevent the computer going to sleep when sound is playing? How can I reset the idle time from the command line?
Вот что я придумала. Он использует команду caffeinate
из пакета кофеина , который вы уже используете.
#!/bin/bash
while true
do
pacmd list-sink-inputs | grep 'RUNNING' > /dev/null
if [ $? -eq 0 ]
then
caffeinate sleep 1
fi
sleep 20
done
Другое решение с использованием xdotool
. Если что-то играло, оно слегка перемещает мышь, а вы не замечаете и оставляете ее там, где она была.
#!/bin/bash
while true
do
pacmd list-sink-inputs | grep 'RUNNING' > /dev/null
if [ $? -eq 0 ]
then
for ANGLE in 0 90 180 270
do
xdotool mousemove_relative --polar $ANGLE 0.1
done
fi
sleep 20
done
Просто убедитесь, что у вас установлено xdotool
:
sudo apt install xdotool