From 556e3742360675a3549f11293737fbe2872d5990 Mon Sep 17 00:00:00 2001 From: Krzysztof Rudnicki Date: Thu, 23 Jan 2025 17:51:37 +0100 Subject: [PATCH] feat: add script toggle mic --- i3-configuration/i3/config | 3 +++ scripts/toggle_mic.sh | 48 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100755 scripts/toggle_mic.sh diff --git a/i3-configuration/i3/config b/i3-configuration/i3/config index b7c710e..b1ad428 100644 --- a/i3-configuration/i3/config +++ b/i3-configuration/i3/config @@ -41,6 +41,9 @@ bindsym XF86AudioLowerVolume exec --no-startup-id /home/kuchy/volume_control.sh bindsym XF86AudioMute exec --no-startup-id pactl set-sink-mute @DEFAULT_SINK@ toggle && $refresh_i3status bindsym XF86AudioMicMute exec --no-startup-id pactl set-source-mute @DEFAULT_SOURCE@ toggle && $refresh_i3status +# Add a key binding to toggle the microphone +bindsym $mod+m exec --no-startup-id /home/kuchy/i3-configuration/scripts/toggle_mic.sh + # Use Mouse+$mod to drag floating windows to their wanted position floating_modifier $mod diff --git a/scripts/toggle_mic.sh b/scripts/toggle_mic.sh new file mode 100755 index 0000000..b824dfb --- /dev/null +++ b/scripts/toggle_mic.sh @@ -0,0 +1,48 @@ +#!/bin/bash + +# Check if amixer is installed, if not, install it +if ! command -v amixer &> /dev/null; then + echo "amixer could not be found, installing..." + sudo pacman -S --noconfirm alsa-utils +fi + +# Ensure dbus is running +if ! pgrep -x "dbus-daemon" > /dev/null; then + echo "Starting dbus..." + sudo systemctl start dbus +fi + +# Ensure dbus is properly initialized for the user session +export $(dbus-launch) + +# Ensure notification-daemon is installed +if ! pacman -Qs notification-daemon > /dev/null; then + echo "Installing notification-daemon..." + sudo pacman -S --noconfirm notification-daemon +fi + +# Ensure dunst is installed and running +if ! pacman -Qs dunst > /dev/null; then + echo "Installing dunst..." + sudo pacman -S --noconfirm dunst +fi + +if ! pgrep -x "dunst" > /dev/null; then + echo "Starting dunst..." + dunst & +fi + +# Get the current state of the microphone +MIC_STATE=$(amixer get Capture | grep '\[on\]') + +if [ -z "$MIC_STATE" ]; then + # If the microphone is off, turn it on + amixer set Capture cap + sleep 1 # Add a delay to ensure notify-send works correctly + notify-send "Microphone" "Microphone is now ON" +else + # If the microphone is on, turn it off + amixer set Capture nocap + sleep 1 # Add a delay to ensure notify-send works correctly + notify-send "Microphone" "Microphone is now OFF" +fi