This commit is contained in:
mr0xb 2026-06-03 14:36:50 -04:00
commit 715eb53860
No known key found for this signature in database
57 changed files with 7755 additions and 3 deletions

View file

@ -0,0 +1,35 @@
#!/bin/bash
# Filename: ~/github/dotfiles-latest/sketchybar/felixkratz/plugins/mic.sh
# https://github.com/FelixKratz/SketchyBar/discussions/12#discussioncomment-1216899
source "$CONFIG_DIR/colors.sh"
# Attempt to get the current input device name
MIC_NAME=$(SwitchAudioSource -t input -c)
# I just want the first word, in case it's too long
MIC_NAME=$(echo $MIC_NAME | awk '{print $1}')
# When no microphone is connected, SwitchAudioSource gives me back random
# characters and sketchybar shows "Warning: Malformed UTF-8 string"
# Validate MIC_NAME as UTF-8, replace invalid sequences with a '?', then compare with original
VALIDATED_MIC_NAME=$(echo "$MIC_NAME" | iconv -f UTF-8 -t UTF-8//IGNORE)
# Get the current microphone volume
MIC_VOLUME=$(osascript -e 'input volume of (get volume settings)')
# Check if MIC_NAME is not meaningful
if [[ "$MIC_NAME" != "$VALIDATED_MIC_NAME" || -z "$MIC_NAME" ]]; then
# If the mic name is not valid or empty
sketchybar -m --set mic label="" icon= icon.color=$YELLOW label.color=$YELLOW
else
# Update SketchyBar with the microphone's name and volume
if [[ $MIC_VOLUME -eq 0 ]]; then
sketchybar -m --set mic label="$MIC_NAME $MIC_VOLUME" icon= icon.color=$RED label.color=$RED
elif [[ $MIC_VOLUME -gt 0 && $MIC_VOLUME -lt 100 ]]; then
sketchybar -m --set mic label="$MIC_NAME $MIC_VOLUME" icon= icon.color=$ORANGE label.color=$ORANGE
elif [[ $MIC_VOLUME -eq 100 ]]; then
sketchybar -m --set mic label="$MIC_NAME $MIC_VOLUME" icon= icon.color=$GREEN label.color=$WHITE
fi
fi

View file

@ -0,0 +1,16 @@
#!/bin/bash
source "$CONFIG_DIR/colors.sh"
MIC_VOLUME=$(osascript -e 'input volume of (get volume settings)')
if [[ $MIC_VOLUME -eq 0 ]]; then
ICON=" "
COLOR=$RED
#sketchybar -m --set mic icon.color=$RED icon= icon.font="0xProto Nerd Font Mono:Bold:20"
elif [[ $MIC_VOLUME -gt 0 ]]; then
ICON=" "
COLOR=$GREEN
fi
#sketchybar -m --set mic icon= icon.color=$GREEN icon.font="0xProto Nerd Font Mono:Bold:25"
sketchybar -m --set mic icon="$ICON" icon.color="$COLOR" icon.font="0xProto Nerd Font Mono:Bold:30"

View file

@ -0,0 +1,64 @@
#!/bin/bash
# Filename: ~/github/dotfiles-latest/sketchybar/felixkratz/plugins/mic_click.sh
# https://github.com/FelixKratz/SketchyBar/discussions/12#discussioncomment-1216899
source "$CONFIG_DIR/colors.sh"
# This is basically the same as the `toggle_devices()` function in:
# ~/github/dotfiles-latest/sketchybar/felixkratz/plugins/volume_click.sh
toggle_mics() {
which SwitchAudioSource >/dev/null || exit 0
source "$CONFIG_DIR/colors.sh"
args=(--remove '/mic.device\.*/' --set "$NAME" popup.drawing=toggle popup.align=left popup.horizontal=on)
COUNTER=0
CURRENT="$(SwitchAudioSource -t input -c)"
while IFS= read -r device; do
COLOR=$GREY
if [ "${device}" = "$CURRENT" ]; then
COLOR=$WHITE
fi
args+=(--add item mic.device.$COUNTER popup."$NAME"
--set mic.device.$COUNTER label="${device}"
label.color="$COLOR"
click_script="SwitchAudioSource -t input -s \"${device}\" && sketchybar --set /mic.device\.*/ label.color=$GREY --set \$NAME label.color=$WHITE --set $NAME popup.drawing=off")
COUNTER=$((COUNTER + 1))
done <<<"$(SwitchAudioSource -a -t input)"
sketchybar -m "${args[@]}" >/dev/null
}
if [ "$BUTTON" = "left" ]; then
# Attempt to get the current input device name
MIC_NAME=$(SwitchAudioSource -t input -c)
# I just want the first word, in case it's too long
MIC_NAME=$(echo $MIC_NAME | awk '{print $1}')
# When no microphone is connected, SwitchAudioSource gives me back random
# characters and sketchybar shows "Warning: Malformed UTF-8 string"
# Validate MIC_NAME as UTF-8, replace invalid sequences with a '?', then compare with original
VALIDATED_MIC_NAME=$(echo "$MIC_NAME" | iconv -f UTF-8 -t UTF-8//IGNORE)
# Get the current microphone volume
MIC_VOLUME=$(osascript -e 'input volume of (get volume settings)')
# Check if MIC_NAME is not meaningful
if [[ "$MIC_NAME" != "$VALIDATED_MIC_NAME" || -z "$MIC_NAME" ]]; then
# If the mic name is not valid or empty
sketchybar -m --set mic label="" icon=
else
# Update SketchyBar with the microphone's name and volume
if [[ $MIC_VOLUME -lt 100 ]]; then
osascript -e 'set volume input volume 100'
sketchybar -m --set mic label="$MIC_NAME 100" icon= icon.color=$GREEN label.color=$WHITE
elif [[ $MIC_VOLUME -gt 0 ]]; then
osascript -e 'set volume input volume 0'
sketchybar -m --set mic label="$MIC_NAME 0" icon= icon.color=$RED label.color=$RED
fi
fi
# Check for right-click or shift modifier to show the microphone selection popup
elif [ "$BUTTON" = "right" ] || [ "$MODIFIER" = "shift" ]; then
toggle_mics
fi

View file

@ -0,0 +1,18 @@
#!/bin/bash
source "$CONFIG_DIR/colors.sh"
MIC_VOLUME=$(osascript -e 'input volume of (get volume settings)')
if [[ $MIC_VOLUME -eq 0 ]]; then
osascript -e 'set volume input volume 25'
ICON=""
COLOR=$GREEN
#sketchybar -m --set mic icon="" icon.color=$GREEN
elif [[ $MIC_VOLUME -gt 0 ]]; then
osascript -e 'set volume input volume 0'
ICON=""
COLOR=$RED
#sketchybar -m --set mic icon="" icon.color=$RED
fi
sketchybar -m --set mic icon="$ICON" icon.color=$COLOR