Last active
February 6, 2024 10:09
-
-
Save tinywrkb/04e7fd644afa9b92d33a3a99ab07ee9e to your computer and use it in GitHub Desktop.
NOT NEEDED WITH 0.3.21 OR GIT VERSION | PipeWire Pulse Server Bluetooth Auto-Switch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# ~/.local/bin/btswitch | |
# | |
# wait a second this is too fast for udev | |
sleep 1 | |
btdev="$(pactl list sinks|grep Name|grep 'bluez.*.a2dp.sink'|sed 's/Name: //'|sed 's/\s//')" | |
if [ -n "$btdev" ]; then | |
echo "Found bluetooth device: $btdev" | |
else | |
echo "Could not find bluetooth device, exiting..." | |
exit 1 | |
fi | |
echo "Setting default sink to the found bluetooth device..." | |
echo "Running pactl set-default-sink $btdev" | |
pactl set-default-sink "$btdev" | |
echo "Setting default volume of sink to 26%" | |
pactl set-sink-volume @DEFAULT_SINK@ 26% | |
echo "Moving all sink inputs to the default sink..." | |
for i in $(pactl list sink-inputs|grep 'Sink Input'|sed 's/Sink Input #//'); do | |
echo "Moving sink input $i to the default sink..." | |
pactl move-sink-input $i @DEFAULT_SINK@ | |
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# ~/.config/systemd/user/pipewire-pulse-bt-switch.service | |
# | |
[Unit] | |
Description=Pipewire Pulse Server Auto Switch to Bluetooth | |
[Service] | |
ExecStart=%h/.local/bin/btswitch | |
[Install] | |
WantedBy=default.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# /etc/udev/rules.d/pipewire-pulse-bt.rules | |
# | |
# phys: bt controller mac | |
# name: bt device name | |
SUBSYSTEM=="input",ATTRS{phys}=="0c:54:15:b5:cf:ec",ATTR{name}=="Bose SoundSport (AVRCP)",ACTION=="add",TAG+="systemd",ENV{SYSTEMD_USER_WANTS}+="pipewire-pulse-bt-switch.service" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How do I get
ATTRS{phys}
&ATTR{name}
of my bluetooth device ?