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?
Here is what I came up with. It uses
caffeinate
command from caffeine package which you are already using.Another solution using
xdotool
. If something was playing it slightly moves the mouse without you noticing and leaves it where it was.Just make sure you've got
xdotool
installed: