Skip to content

Instantly share code, notes, and snippets.

@fernvenue
Last active August 21, 2024 07:15
Show Gist options
  • Save fernvenue/e2bec79935777207a419b41da87ec5f3 to your computer and use it in GitHub Desktop.
Save fernvenue/e2bec79935777207a419b41da87ec5f3 to your computer and use it in GitHub Desktop.
Mute system sounds when lock the screen on Debian GNOME.
[Unit]
Description=Mute When Lock
After=default.target
[Service]
ExecStart=/usr/local/bin/mute-when-lock.sh
Restart=on-failure
[Install]
WantedBy=default.target
#!/bin/bash
# Mute;
mute() {
amixer set Master mute > /dev/null 2>&1
echo "Screen Locked, Sound Muted."
}
# Unmute;
unmute() {
amixer set Master unmute > /dev/null 2>&1
echo "Screen Unlocked, Sound Unmuted."
}
# Listen for the screen lock/unlock signal;
dbus-monitor --session "type='signal',interface='org.gnome.ScreenSaver',member='ActiveChanged'" | \
while read -r line; do
if echo "$line" | grep -q "boolean true"; then
mute
elif echo "$line" | grep -q "boolean false"; then
unmute
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment