-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup_mic_mute.sh
executable file
·63 lines (49 loc) · 1.9 KB
/
setup_mic_mute.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/bin/bash
# Define variables
UDEV_RULE_FILE="/etc/udev/rules.d/99-micmute.rules"
TOGGLE_SCRIPT="/usr/local/bin/toggle_mic_mute.sh"
HYPRLAND_CONFIG="$HOME/.config/hypr/hyprland.conf"
# Create udev rule
echo "Creating udev rule..."
echo 'SUBSYSTEM=="leds", KERNEL=="platform::micmute", MODE="0660", GROUP="users"' | sudo tee $UDEV_RULE_FILE
# Reload udev rules
echo "Reloading udev rules..."
sudo udevadm control --reload-rules
sudo udevadm trigger
sudo chmod 666 /sys/class/leds/platform::micmute/brightness
# Add current user to 'users' group
echo "Adding current user to 'users' group..."
sudo usermod -aG users $USER
# Create the toggle script
echo "Creating toggle script..."
sudo tee $TOGGLE_SCRIPT > /dev/null << 'EOF'
#!/bin/bash
# Get the default source (microphone)
DEFAULT_SOURCE=$(pactl info | grep 'Default Source' | cut -d ' ' -f3)
# Toggle mute state
pactl set-source-mute "$DEFAULT_SOURCE" toggle
# Check the current mute state
MUTE_STATE=$(pactl get-source-mute "$DEFAULT_SOURCE")
if [[ "$MUTE_STATE" == "Mute: yes" ]]; then
# Microphone is muted, turn off the indicator light
echo 0 > /sys/class/leds/platform::micmute/brightness
else
# Microphone is unmuted, turn on the indicator light
echo 1 > /sys/class/leds/platform::micmute/brightness
fi
EOF
# Make the script executable
echo "Making the toggle script executable..."
sudo chmod +x $TOGGLE_SCRIPT
# Add binding to Hyprland config
echo "Adding key binding to Hyprland config..."
mkdir -p "$(dirname "$HYPRLAND_CONFIG")"
if ! grep -q "bind =, XF86AudioMicMute" "$HYPRLAND_CONFIG"; then
echo "bind =, XF86AudioMicMute, exec, $TOGGLE_SCRIPT" >> "$HYPRLAND_CONFIG"
else
echo "Key binding already exists in $HYPRLAND_CONFIG"
fi
# Reload Hyprland configuration
echo "Reloading Hyprland configuration..."
hyprctl reload
echo "Setup complete. Please log out and log back in for group changes to take effect, then test the microphone mute key."