-
Notifications
You must be signed in to change notification settings - Fork 37
Refactor audio_switch script: Pipewire and Bluetooth Connectivity #21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Refactor audio_switch script: Pipewire and Bluetooth Connectivity #21
Conversation
|
Thanks @alpheratz0 for your reviews — I’ve applied the suggested changes to my code. |
| enable_and_connect "DEVICE NAME" | ||
| set_source "SET SINK NAME OR DEVICE ID" | ||
| # the source ID will change every time you connect a bluetooth device, so you may need to change this often | ||
| # might need to do a function to get the source ID or name dynamically |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe find a workaround for this? is this only a problem for pipewire users?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have found a workaround for this, just need to test on both audio server. And no its for both audio server not only pipewire (the id change everytime I disabled bluetooth and re-enable it)
Here is the workaround to get the id:
get_sink_number() {
local DEVICE_NAME="$1"
if systemctl --user is-active pipewire >/dev/null 2>&1; then
wpctl status | awk -v target="$DEVICE_NAME" '/Sinks:/, /Sink endpoints:/ {
if ($2 == "*") {
if ($4 == target) print $3
} else {
if ($3 == target) print $2
}
}' | tr -d '.'
elif systemctl --user is-active pulseaudio >/dev/null 2>&1; then
pactl list sinks | awk -v dev="$DEVICE_NAME" '
/Sink #/ { sink = substr($2, 2) }
$0 ~ dev { print sink; exit }
'
else
notify-send "No audio system detected. Please ensure PipeWire or PulseAudio is running."
return 1
fi
}And here how I plan to use it :
bluetooth () { \
enable_and_connect "WH-1000XM4"
local sink_num=$(get_sink_number "WH-1000XM4")
set_source "$sink_num"
notify-send -h string:bgcolor:#88c0d0 "Audio switched to bluetooth!"
}|
Hey, thanks for your work on this! For compatibility, it may be better to avoid calling systemctl, for those who don't use systemd. Could instead just check to see if a pid exists for either process. Sadly atm I don't have a bluetooth device to check with, for the workaround with id. I'll leave this open for now if anyone does feel like testing that or improving further :) |
|
Can try with if pgrep -x pipewire >/dev/null 2>&1; then
# code ...
elif pgrep -x pulseaudio >/dev/null 2>&1; then
# code ...
else
# code ...
fi |
Hey, really loved your scripts, so i decide to make some changes to the
dmenu_audioswitch_prevscript with improved audio device switching capabilities and broader compatibility.Changes
Testing
Impact
These changes make the script more versatile for modern Linux audio setups while maintaining backward compatibility with existing PulseAudio workflows.