Skip to content

Instantly share code, notes, and snippets.

@dsl400
Created February 23, 2025 17:50
Show Gist options
  • Select an option

  • Save dsl400/6ee953acdf76a20fc42793dc3955a72e to your computer and use it in GitHub Desktop.

Select an option

Save dsl400/6ee953acdf76a20fc42793dc3955a72e to your computer and use it in GitHub Desktop.
OSD message for microphone on
GNU nano 7.2 /etc/systemd/system/mic_monitor.service
[Unit]
Description=Microphone Status Monitor Service
After=graphical.target sound.target
[Service]
Type=simple
# Set the display so aosd_cat knows where to show the output.
Environment=DISPLAY=:0
Environment=XDG_RUNTIME_DIR=/run/user/1000
# If necessary, also specify XAUTHORITY:
# Environment=XAUTHORITY=/home/dsl400/.Xauthority
ExecStart=/usr/local/bin/mic_monitor.sh
Restart=always
User=dsl400
[Install]
WantedBy=default.target
#!/bin/bash
prev_state="unknown"
aosd_pid=""
while IFS= read -r event; do
# Check if any non-monitor source is RUNNING
if pactl list sources short | grep -v monitor | grep -q RUNNING; then
current_state="on"
else
current_state="off"
fi
if [ "$current_state" != "$prev_state" ]; then
if [ "$current_state" = "on" ]; then
# Only start if not already running
if [ -z "$aosd_pid" ]; then
echo 'MIC ON!' | aosd_cat -u 999999 -p 7 -R red -y "-100" -n "Propmt Bold Black 48" -r 80 -s 50 -B black -b 50 -d 16 &
aosd_pid=$!
fi
else
# If the mic is muted, kill the aosd_cat process to hide the notification
if [ -n "$aosd_pid" ]; then
kill "$aosd_pid" 2>/dev/null
aosd_pid=""
fi
fi
prev_state="$current_state"
fi
done < <(pactl subscribe)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment