Last active
August 21, 2024 07:15
-
-
Save fernvenue/e2bec79935777207a419b41da87ec5f3 to your computer and use it in GitHub Desktop.
Mute system sounds when lock the screen on Debian GNOME.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Unit] | |
Description=Mute When Lock | |
After=default.target | |
[Service] | |
ExecStart=/usr/local/bin/mute-when-lock.sh | |
Restart=on-failure | |
[Install] | |
WantedBy=default.target |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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