I have following set-up of audio and video devices connected via HDMI cables:

laptop --> AV receiver with speakers --> LCD display

When my screen goes black due to inactivity, also sound disappears. It works the same way on Windows, so I've got used to it. When I move the mouse, both video and sound returns.

However, after recent upgrade from Ubuntu 14.04 to 16.04, sound output device is being switched to analog laptop speakers, when screensaver gets deactivated. Any ideas how to solve it?

Many thanks, zbig

  • I think it should be possible to tell PulseAudio somehow that HDMI is the default output or has priority somehow, so that it will switch back to it when HDMI out returns. – JanC Apr 25 '16 at 21:52

OK, so after a couple of hours of digging through the Internet and learning shell scripting, I've mashed-up the script below, which brutally switches sound output device to what I want.

//edit: I've also added test, if HDMI cable is connected


while sleep 5s ; do
    SCR_SAVER_STATE=$(gnome-screensaver-command --query | grep -o "\w*active\w*")

    if [ "$SCR_SAVER_STATE" = "active" ]
        # switch to speakers, if screensaver is active
        pacmd set-card-profile 0 "output:analog-stereo+input:analog-stereo"
        # check, if HDMI output is available (cable connected)
        # if YES switch to HDMI, or to Speakers otherwise
        HDMI_AVAILABLE=$(pacmd list-cards | grep "hdmi-output-0" | cut -d ' ' -f 12- | rev | cut -c 2- | rev)

        if [ "$HDMI_AVAILABLE" = "yes" ]
            pacmd set-card-profile 0 "output:hdmi-stereo+input:analog-stereo"
            pacmd set-card-profile 0 "output:analog-stereo+input:analog-stereo"

I've saved the script in my home directory and added it to Startup Applications.

I guess it's very inelegant solution to the problem, but at least it works. The script is customized for my hardware, so if you have the same problem, then you'll have to find out what are your sound output profiles. You can find all profiles running following command:

pacmd list-cards

You can also find your active profile by running this:

pacmd list-cards | grep "active profile" | cut -d ' ' -f 3-

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.