Skip to content

Instantly share code, notes, and snippets.

@tinywrkb
Last active May 14, 2025 08:35
Show Gist options
  • Save tinywrkb/04e7fd644afa9b92d33a3a99ab07ee9e to your computer and use it in GitHub Desktop.
Save tinywrkb/04e7fd644afa9b92d33a3a99ab07ee9e to your computer and use it in GitHub Desktop.

Revisions

  1. tinywrkb revised this gist Jan 27, 2021. No changes.
  2. tinywrkb revised this gist Jan 12, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion btswitch
    Original file line number Diff line number Diff line change
    @@ -6,7 +6,7 @@
    # wait a second this is too fast for udev
    sleep 1

    btdev="$(pactl list sinks|grep Name|grep 'bluez5.a2dp.sink'|sed 's/Name: //'|sed 's/\s//')"
    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
  3. tinywrkb revised this gist Nov 17, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion btswitch
    Original file line number Diff line number Diff line change
    @@ -23,6 +23,6 @@ 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 all sink input $i to the default sink..."
    echo "Moving sink input $i to the default sink..."
    pactl move-sink-input $i @DEFAULT_SINK@
    done
  4. tinywrkb revised this gist Nov 17, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion pipewire-pulse-bt.rules
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    #
    # /etc/udev/rules.d/pipewire-pulse-bt.rule
    # /etc/udev/rules.d/pipewire-pulse-bt.rules
    #
    # phys: bt controller mac
    # name: bt device name
  5. tinywrkb revised this gist Nov 17, 2020. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion pipewire-pulse-bt.rules
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,6 @@
    #
    # /etc/udev/rules.d/pipewire-pulse-bt.rule
    #
    SUBSYSTEM=="input",ATTRS{phys}=="0c:54:15:b5:cf:ec",ACTION=="add",TAG+="systemd",ENV{SYSTEMD_USER_WANTS}+="pipewire-pulse-bt-switch.service"
    # 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"
  6. tinywrkb revised this gist Nov 17, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion btswitch
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,7 @@
    # ~/.local/bin/btswitch
    #

    # wait a second this is too fast for udev
    # wait a second this is too fast for udev
    sleep 1

    btdev="$(pactl list sinks|grep Name|grep 'bluez5.a2dp.sink'|sed 's/Name: //'|sed 's/\s//')"
  7. tinywrkb revised this gist Nov 17, 2020. 2 changed files with 1 addition and 2 deletions.
    1 change: 0 additions & 1 deletion btswitch
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,4 @@
    #!/bin/bash

    #
    # ~/.local/bin/btswitch
    #
    2 changes: 1 addition & 1 deletion pipewire-pulse-bt.rules
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    #/etc/udev/rules.d/
    #
    # /etc/udev/rules.d/pipewire-pulse-bt.rule
    #
    SUBSYSTEM=="input",ATTRS{phys}=="0c:54:15:b5:cf:ec",ACTION=="add",TAG+="systemd",ENV{SYSTEMD_USER_WANTS}+="pipewire-pulse-bt-switch.service"
  8. tinywrkb created this gist Nov 17, 2020.
    29 changes: 29 additions & 0 deletions btswitch
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    #!/bin/bash

    #
    # ~/.local/bin/btswitch
    #

    # wait a second this is too fast for udev
    sleep 1

    btdev="$(pactl list sinks|grep Name|grep 'bluez5.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 all sink input $i to the default sink..."
    pactl move-sink-input $i @DEFAULT_SINK@
    done
    11 changes: 11 additions & 0 deletions pipewire-pulse-bt-switch.service
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    #
    # ~/.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
    4 changes: 4 additions & 0 deletions pipewire-pulse-bt.rules
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,4 @@
    #/etc/udev/rules.d/
    # /etc/udev/rules.d/pipewire-pulse-bt.rule
    #
    SUBSYSTEM=="input",ATTRS{phys}=="0c:54:15:b5:cf:ec",ACTION=="add",TAG+="systemd",ENV{SYSTEMD_USER_WANTS}+="pipewire-pulse-bt-switch.service"