How to (re)set the idle time?

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?

2
задан 9 July 2020 в 12:20

1 ответ

Вот что я придумала. Он использует команду 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
3
ответ дан 30 July 2020 в 22:11

Другие вопросы по тегам:

Похожие вопросы: