updated status bar

This commit is contained in:
2025-08-15 16:36:05 +02:00
parent 6a3de0df23
commit 1b88c5cc71
7 changed files with 443 additions and 268 deletions

118
waybar/scripts/bluetooth_audio.sh Executable file
View File

@@ -0,0 +1,118 @@
#!/bin/bash
bt-audio-info() {
# Check if a MAC address was provided as the first argument.
if [ -z "$1" ]; then
echo "Usage: $0 <MAC_ADDRESS>"
echo "Example: $0 00:11:22:33:AA:BB"
exit 1
fi
MAC_ADDRESS="$1"
# --- Main Logic ---
# Construct the PipeWire sink name from the MAC address.
# The format is typically: bluez_output.XX_XX_XX_XX_XX_XX.a2dp_sink
# We replace colons with underscores for the format.
SINK_IDENTIFIER="bluez_output.$(echo "$MAC_ADDRESS" | tr ':' '_')"
# Use pactl to get the full details for all sinks, then find the one
# that contains our device's identifier. We use awk to print the
# entire block of text for that specific sink.
# We check for a partial match on the sink identifier because the profile
# (e.g., .a2dp_sink) can change.
sink_info=$(pactl list sinks | awk -v id="$SINK_IDENTIFIER" '/Sink #/ {p=0} $0 ~ "Name: " id {p=1} p')
# If sink_info is empty, the device might not be an audio sink or isn't connected.
if [ -z "$sink_info" ]; then
echo "Error: Could not find an active audio sink for MAC ${MAC_ADDRESS}"
echo "Please ensure the device is connected and is an audio output device."
exit 1
fi
# Get the full block of info for the device from bluetoothctl.
device_info=$(bluetoothctl info "$MAC_ADDRESS")
# --- Parse Information ---
# Parse bluetoothctl output for general device details.
alias=$(echo "$device_info" | rg "Alias:" | cut -d ' ' -f 2-)
trusted=$(echo "$device_info" | rg "Trusted:" | awk '{print $2}')
battery_raw=$(echo "$device_info" | rg "Battery Percentage:" | awk -F'[()]' '{print $2}')
# Parse pactl output for audio-specific details.
volume=$(echo "$sink_info" | rg "Volume:" | head -n1 | awk '{print $5}')
codec=$(echo "$sink_info" | rg -e 'bluetooth.codec|api.bluez5.codec' | awk -F'"' '{print $2}')
# --- Build and Display Compact Output ---
# Build the output string with all the information.
output_string="${alias} | MAC: ${MAC_ADDRESS}\n"
output_string+="Trusted: ${trusted}"
# Append battery info if available, otherwise show N/A.
if [ -n "$battery_raw" ]; then
output_string+=" | Bat: ${battery_raw}%"
else
output_string+=" | Bat: N/A"
fi
output_string+=" | Vol: ${volume} | Codec: ${codec:-N/A}"
# Print the final, single-line string.
echo "$output_string"
}
# Find the MAC address of the first connected device that is an audio sink
find_audio_device() {
default_sink_name=$(pactl get-default-sink)
# Check if the default sink is a Bluetooth device. Their names typically
# start with "bluez_output.". If not, print a message and exit.
if [[ "$default_sink_name" == bluez_output* ]]; then
# Extract the MAC address from the sink name.
# The format is bluez_output.XX_XX_XX_XX_XX_XX.profile
# We extract the middle part and replace underscores with colons.
mac_with_underscores=$(echo "$default_sink_name" | cut -d '.' -f 2)
mac=$(echo "$mac_with_underscores" | tr '_' ':')
echo "$mac"
return
fi
# else look for the first bluetooth device that provides a sink
bluetoothctl devices Connected | rg '^Device ' | awk '{print $2}' | while read -r mac;
do
# Check if the device provides the "Audio Sink" service
if bluetoothctl info "$mac" | rg -q "0000110b-0000-1000-8000-00805f9b34fb"; then
echo "$mac"
# If you only want the first audio device found, you can 'break' or 'exit' here.
break
fi
done
}
# If the script is called with "disconnect"
if [ "$1" == "disconnect" ]; then
device_mac=$(find_audio_device)
if [ -n "$device_mac" ]; then
bluetoothctl disconnect "$device_mac"
fi
echo "{}"
exit 0
fi
# Main logic to display the device name
device_mac=$(find_audio_device)
if [ -n "$device_mac" ]; then
# Get the device alias (name)
device_name=$(bluetoothctl info "$device_mac" | rg "Alias:" | cut -d ' ' -f 2-)
# Output in Waybar's JSON format
tooltip=$(bt-audio-info $device_mac)
echo "{\"text\": \"$device_name <span size='large'>󰂰</span>\", \"tooltip\": \"$tooltip\"}"
else
# Output empty string when no device is connected
echo "{}"
fi

View File

@@ -0,0 +1,113 @@
#!/bin/bash
# --- CONFIGURATION ---
# Your Pixel Buds Pro's MAC Address
MAC_ADDRESS="B4:23:A2:09:D3:53"
# --- END CONFIGURATION ---
not_connected() {
printf '{"text": "L: --- | R: --- | Off", "tooltip": "Pixel Buds Pro 2", "class": "disconnected"}\n'
exit 0
}
status() {
# First, check if the device is connected using bluetoothctl.
if bluetoothctl info "$MAC_ADDRESS" | grep -q "Connected: yes"; then
# --- DEVICE IS CONNECTED ---
# This function gets the current status and formats it for Waybar.
get_status() {
# Get all info from pbpctrl in one go. Redirect errors to null.
battery_output=$(pbpctrl show battery 2>/dev/null)
# Fallback: If pbpctrl fails or returns 'unknown', hide the module.
if [[ $? -ne 0 || -z "$battery_output" ]]; then
not_connected
fi
# --- PARSE BATTERY INFO ---
left_bud=$(echo "$battery_output" | grep "left bud:" | awk '{print $3}')
right_bud=$(echo "$battery_output" | grep "right bud:" | awk '{print $3}')
if ([[ "$left_bud" == "unknown" ]] && [[ "$right_bud" == "unknown" ]]) || \
[[ -z "$left_bud" && -z "$right_bud" ]]; then
echo "{}"
exit 0
fi
if [[ "$left_bud" == "unknown" ]]; then
left_display="L: ---"
else
left_display="L: $left_bud"
fi
if [[ "$right_bud" == "unknown" ]]; then
right_display="R: ---"
else
right_display="R: $right_bud"
fi
# --- PARSE ANC INFO ---
current_mode=$(pbpctrl get anc 2>/dev/null)
case "$current_mode" in
"active")
anc_icon="ANC"
class="anc-active"
;;
"aware")
anc_icon="Aware"
class="anc-aware"
;;
"off")
anc_icon="Off"
class="anc-off"
;;
*)
anc_icon="?"
class="anc-unknown"
;;
esac
# --- FORMAT OUTPUT ---
printf '{"text": "%s | %s | %s", "tooltip": "Pixel Buds Pro 2", "class": "%s"}\n' \
"$left_display" "$right_display" "$anc_icon" "$class"
}
get_status
else
# --- DEVICE IS NOT CONNECTED ---
not_connected
fi
}
# Handle click actions passed from Waybar.
case "$1" in
cycle_anc)
current_mode=$(pbpctrl get anc 2>/dev/null)
next_mode=""
case "$current_mode" in
active)
next_mode="aware"
;;
aware)
next_mode="off"
;;
off)
next_mode="active"
;;
esac
pbpctrl set anc "$next_mode"
sleep 0.1
;;
connect)
bluetoothctl connect "$MAC_ADDRESS" & disown
;;
disconnect)
bluetoothctl disconnect "$MAC_ADDRESS" & disown
;;
*)
status
;;
esac

View File

@@ -1,54 +0,0 @@
#!/bin/bash
# Script to manage and display system76-power profiles for Waybar
# Define the available power profiles
PROFILES=("Performance" "Balanced" "Battery")
# Get the current power profile
CURRENT_PROFILE=$(system76-power profile | awk '/Power Profile/ {print $3}')
# Function to switch to the next profile
switch_next_profile() {
# Find the index of the current profile
for i in "${!PROFILES[@]}"; do
if [[ "${PROFILES[$i]}" == "$CURRENT_PROFILE" ]]; then
current_index=$i
break
fi
done
# Calculate the index of the next profile
next_index=$(((current_index + 1) % ${#PROFILES[@]}))
NEXT_PROFILE=${PROFILES[$next_index]}
# Switch to the next profile
system76-power profile "$NEXT_PROFILE"
}
# If the script is called with "next", switch the profile
if [[ "$1" == "next" ]]; then
switch_next_profile
# After switching, get the new current profile
CURRENT_PROFILE=$(system76-power profile | awk '/Power Profile/ {print $3}')
fi
# Set an icon based on the current profile
case $CURRENT_PROFILE in
"Performance")
ICON="🚀"
;;
"Balanced")
ICON="⚖️"
;;
"Battery")
ICON="🔋"
;;
*)
ICON="❓"
;;
esac
# Output in JSON format for Waybar
printf '{"text": "%s", "tooltip": "Power Profile: %s", "class": "%s"}\n' "$ICON" "$CURRENT_PROFILE" "$(echo $CURRENT_PROFILE | tr '[:upper:]' '[:lower:]')"

View File

@@ -51,4 +51,4 @@ else # Fallback for "fully-charged", "pending-charge", etc.
fi
# Output JSON for Waybar
printf '{"text": "%s %s%%", "tooltip": "%s", "class": "%s"}\n' "$icon" "$percentage" "$tooltip" "$class"
printf '{"text": "%s%% %s", "tooltip": "%s", "class": "%s"}\n' "$percentage" "$icon" "$tooltip" "$class"