0

I'm working on Ubuntu 18.04, though I'd like to have a way to completely mute sound when I lock my device, this is for 2 differents situations: First avoid someone to unplug my headset and listen to what I was listening to.
Second to avoid my coworkers being annoyed by sound that might come out from my headset if a music is not mixed properly and suddenly shout out. My goal is to not only mute but reliably avoid sound getting out of my computer when it is locked.

0

pactl set-sink-mute @DEFAULT_SINK@ toggle
or
pactl set-sink-mute 0 toggle
if have only one audio sink

if there are multiple sinks, use
pactl list short sinks
for list of sinks sorted by index number

| improve this answer | |
  • ok it's part of the answer thank you for the hint. I have to find a way to disable keyboard shortcut because mute working but the keyboard can still raise sound level. – Kiwy Dec 5 '18 at 13:02
  • you did not mention a laptop with volume keys, or any other relevant hardware information. suggest you read man amixer and try similar mute toggle command for ALSA – nik gnomic Dec 5 '18 at 16:01
0

How to mute sound when xscreensaver locks screen

Nicely mutes and un-mutes lock and unlock. I dunno which is better amixer Vs pactl.

#!/bin/bash

gdbus monitor -y -d org.freedesktop.login1 | grep LockedHint --line-buffered |
    while read line
    do
        case "$line" in
            *"<true>"*)
                #amixer -q -D pulse sset Master off
                pactl set-sink-mute @DEFAULT_SINK@ toggle
            ;;
            *"<false>"*)
                #amixer -q -D pulse sset Master on
                pactl set-sink-mute @DEFAULT_SINK@ toggle
            ;;
        esac
    done
exit

Thanks to all (Nick Gnomic and Cliff Stanford).

Works without xscreensaver installed, confirm works on wayland as well.

| improve this answer | |

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.