I'm trying to use a script that makes it so that the LED mute indicator on my keyboard…
- User
I'm trying to use a script that makes it so that the LED mute indicator on my keyboard syncs to whenever the main sound output is muted/unmuted, not just the built in speaker. I am running Linux Mint 22.1. The problem is the LED mute indicator is now always on, and the only sound output device reported is called "Dummy Output". The script is running in systemd This is the script: #!/bin/bash
LOG="LOG"
Wait for PulseAudio/pipewire to become available
while ! pactl info &>/dev/null; do echo "Waiting for PulseAudio/pipewire..." >> "$LOG" sleep 2 done
Check if card 1 is available and has 'Master'
has_master_control=false if amixer -c 1 scontrols 2>/dev/null | grep -q 'Master'; then has_master_control=true echo "Found card 1 with Master control" >> "LOG" fi
Monitor mute status
pactl subscribe | while read -r line; do if echo "(pactl get-sink-mute @DEFAULT_SINK@ 2>/dev/null) echo "Mute status: LOG" if [[ "mute_status" == "yes" ]]; then amixer -q -c 1 set Master mute echo "Muted (LED ON)" >> "mute_status" == "no" ]]; then amixer -q -c 1 set Master unmute echo "Unmuted (LED OFF)" >> "$LOG" fi fi fi done
- Assistant
The "Dummy Output" issue indicates that your audio system (PulseAudio/PipeWire) isn't detecting your actual audio hardware. This is likely caused by the script or systemd service interfering with the audio system initialization. Let's fix this step by step.
First, let's diagnose and fix the audio issue:
- Stop the problematic service:
sudo systemctl stop your-mute-led-service-name sudo systemctl disable your-mute-led-service-name- Restart your audio system:
systemctl --user restart pulseaudio # Or if using pipewire: systemctl --user restart pipewire pipewire-pulse- Check if your audio devices are back:
pactl list short sinks aplay -lIf audio is still broken, try:
# Kill all audio processes pulseaudio -k # Remove PulseAudio config rm -rf ~/.config/pulse # Restart pulseaudio --startOnce your audio is working again, let's fix the script and systemd service:
Improved script (
/usr/local/bin/mute-led-sync.sh):#!/bin/bash LOG="$HOME/mute-led.log" echo "[$(date)] Starting mute LED sync..." >> "$LOG" # Wait longer for audio system to fully initialize sleep 10 # More robust audio system check for i in {1..30}; do if pactl info &>/dev/null && pactl list short sinks | grep -v dummy &>/dev/null; then echo "[$(date)] Audio system ready" >> "$LOG" break fi echo "[$(date)] Waiting for audio system... attempt $i" >> "$LOG" sleep 2 done # Check if card 1 is available and has 'Master' has_master_control=false if amixer -c 1 scontrols 2>/dev/null | grep -q 'Master'; then has_master_control=true echo "[$(date)] Found card 1 with Master control" >> "$LOG" else echo "[$(date)] Card 1 not available. LED control will be disabled." >> "$LOG" fi # Initial sync if [[ "$has_master_control" == true ]]; then mute_status=$(pactl get-sink-mute @DEFAULT_SINK@ 2>/dev/null) if [[ "$mute_status" == *"yes"* ]]; then amixer -q -c 1 set Master mute else amixer -q -c 1 set Master unmute fi fi # Monitor mute status pactl subscribe | while read -r line; do if echo "$line" | grep -qE "sink.*change"; then mute_status=$(pactl get-sink-mute @DEFAULT_SINK@ 2>/dev/null) echo "[$(date)] Mute status: $mute_status" >> "$LOG" if [[ "$has_master_control" == true ]]; then if [[ "$mute_status" == *"yes"* ]]; then amixer -q -c 1 set Master mute elif [[ "$mute_status" == *"no"* ]]; then amixer -q -c 1 set Master unmute fi fi fi doneSystemd user service (
~/.config/systemd/user/mute-led-sync.service):[Unit] Description=Keyboard Mute LED Sync After=graphical-session.target sound.target Wants=sound.target [Service] Type=simple ExecStart=/usr/local/bin/mute-led-sync.sh Restart=on-failure RestartSec=5 Environment="HOME=%h" Environment="USER=%u" [Install] WantedBy=default.targetSetup instructions:
# Make script executable sudo chmod +x /usr/local/bin/mute-led-sync.sh # Create systemd user directory if needed mkdir -p ~/.config/systemd/user # Copy service file to user systemd directory # Then reload and enable systemctl --user daemon-reload systemctl --user enable mute-led-sync.service systemctl --user start mute-led-sync.serviceThe key improvements:
- Runs as a user service instead of system service (better for audio)
- Waits longer for audio initialization
- Checks for non-dummy sinks before proceeding
- Better logging with timestamps
- Initial sync on startup
If you're still having issues, check the log:
tail -f ~/mute-led.log journalctl --user -u mute-led-sync -f
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.