The problem#
Which window I have focused is a signal to the computer for the state I want it to be in. For instance, I normally leave my speaker muted so, for example, I don't accidentally play sound from a website with unexpected videos. But this means that when I do want sound, I need to manually unmute the sound, even though I've already told the computer that I want to watch Netflix, which always involves turning on the sound.
Of course, for the particular problem of unmuting the sound, adding a keyboard shortcut and rereading xkcd 1205: Is It Worth the Time? probably would have been a more appropriate solution. But I wanted a general solution to the problem.
The solution#
Download x11_watch_active_window.py
.
Then the following script will unmute the speakers if Netflix is
focused:
#!/bin/sh
x11_watch_active_window.py | while read -r FocusApp
do
if [ "Netflix - Google Chrome" = "$FocusApp" ]
then
echo Netflix is focused, unmuting.
pactl set-sink-mute 0 0
fi
done