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.


pactl set-sink-mute @DEFAULT_SINK@ toggle
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

  • 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

How to mute sound when xscreensaver locks screen

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


gdbus monitor -y -d org.freedesktop.login1 | grep LockedHint --line-buffered |
    while read line
        case "$line" in
                #amixer -q -D pulse sset Master off
                pactl set-sink-mute @DEFAULT_SINK@ toggle
                #amixer -q -D pulse sset Master on
                pactl set-sink-mute @DEFAULT_SINK@ toggle

Thanks to all (Nick Gnomic and Cliff Stanford).

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

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.