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"
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
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"elseecho"Card1notavailable.LEDcontrolwillbedisabled.">>"LOG"
fi
Monitor mute status
pactl subscribe | while read -r line; do
if echo "line"∣grep−q"sink";thenmutestatus=(pactl get-sink-mute @DEFAULT_SINK@ 2>/dev/null)
echo "Mute status: mutestatus">>"LOG"
if [[ "hasmastercontrolmute_status" == "yes" ]]; then
amixer -q -c 1 set Master mute
echo "Muted (LED ON)" >> "LOG"elif[["mute_status" == "no" ]]; then
amixer -q -c 1 set Master unmute
echo "Unmuted (LED OFF)" >> "$LOG"
fi
fi
fi
done
Assistant
This kind of behavior (only “Dummy Output” and the LED always on) is very often caused by running the script as a system‐wide service instead of in your user session. In other words, the script is not “seeing” your normal PulseAudio (or PipeWire) session, so when it runs under systemd it lacks the correct environment variables (like XDG_RUNTIME_DIR) and even the user’s PulseAudio socket. As a result, commands like pactl info and pactl get-sink-mute end up “seeing” a dummy sink instead of your real sound device.
Below are several suggestions to resolve the issue:
1. Run the Script as a User Service
Why?
PulseAudio (or PipeWire) normally runs as a per-user daemon. A user service will inherit the proper environment (especially XDG_RUNTIME_DIR), letting pactl talk to your real audio server.
How?
Place your service file in your user directory (for example, in ~/.config/systemd/user/mute-led-sync.service):
ini
[Unit]
Description=Mute LED Sync
[Service]
ExecStart=/home/yourusername/path/to/your/script.sh
Restart=on-failure
[Install]
WantedBy=default.target
Then enable and start the service as your normal user:
2. Export Necessary Environment Variables in the Script
If you need to run it as a system-wide service for some reason, make sure to supply the proper environment variables so that it uses the correct PulseAudio socket. For example, add these lines at the top of your script (after the shebang):
Replace yourusername with the actual user name or use dynamic methods to get the appropriate ID. (Keep in mind that running as root may complicate this; ideally use the user service method.)
3. Verify the Audio Card Being Controlled
Even if your sound output is working, check that the audio card your script references (card 1 with the “Master” control) is correct:
"
==
true]];thenif[["
Run:
bash
amixer -c 1 scontrols
and verify that it lists “Master.”
If your system’s layout has changed (for example, if your relevant card is now card 0), adjust the script accordingly.
You can even consider making the card number configurable or detecting it dynamically.
4. Check for Timing Issues
Your script is waiting for PulseAudio/pipewire to be available by looping on pactl info. When running as a system service, PulseAudio might not have started yet. Running the script as a user service usually helps with this; if not, extend your waiting loop or add a delay to ensure the audio server is up.
Recap
Problem: The “Dummy Output” and the always-on LED indicate that your script is not interfacing with the proper audio session.
Likely Cause: The script running as a system service (with an environment lacking user-specific PulseAudio variables) instead of as a user service.
Solutions:
Run the script as a user-level systemd service.
If necessary, export XDG_RUNTIME_DIR (or other relevant environment variables) so that pactl connects to the correct socket.
Verify that your card and control (e.g., “Master” on card 1) are valid for your hardware.
By adopting these changes you should see the proper mute status, and your LED indicator will correctly reflect the system’s mute state rather than remaining on all the time.