diff options
author | Saren Arterius | 2018-11-17 20:36:46 +0800 |
---|---|---|
committer | Saren Arterius | 2018-11-17 20:36:46 +0800 |
commit | b2dfeae76789c0592c655402c81860903a7c2bae (patch) | |
tree | c8e0cf199de0abdaf4fef61bdf1036719762e29c /bt-auto-enable-a2dp | |
download | aur-b2dfeae76789c0592c655402c81860903a7c2bae.tar.gz |
first
Diffstat (limited to 'bt-auto-enable-a2dp')
-rw-r--r-- | bt-auto-enable-a2dp | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/bt-auto-enable-a2dp b/bt-auto-enable-a2dp new file mode 100644 index 000000000000..970343b72e65 --- /dev/null +++ b/bt-auto-enable-a2dp @@ -0,0 +1,54 @@ +#!/bin/sh + +# Dependencies: +# * bluez-tools +# * expect +# * perl + +export PATH='/usr/bin:/usr/local/bin:/usr/sbin:/usr/local/sbin:'$PATH + +function enable_a2dp() { + # run connect command in bluetoothctl and wait for resolve of services + expect <<< " + spawn bluetoothctl + send \"connect $mac\r\" + log_user 0 + expect -re \".*Device $mac ServicesResolved: yes\" + " + # enable card in pulseaudio + pactl set-card-profile $pulsecard a2dp_sink + logger -p info "mac $mac enabled" + + headsetname=`bt-device -l | perl -ne '/(.*) \('$mac'\)/ and print "$1\n"'` + notify-send 'Headset connected' "$headsetname" --icon=blueman-headset +} + +function search_headsets() { + sleep 1 + # in all added devices + for mac in `bt-device -l | perl -ne '/.*\((.*)\)/ and print "$1\n"'` + do + # search for connected device with AudioSink service + if [[ `bt-device -i $mac | perl -00 -ne '/.*Trusted: 1.*\n\s*Blocked: 0.*\n\s*Connected: 1\n\s*UUIDs: .*AudioSink.*/ and print "1\n"'` ]]; then + logger -p info "found mac: $mac" + # convert mac to pulse card name + pulsecard=`perl -pe 's/:/_/g' <<< "bluez_card.$mac"` + enable_a2dp + fi + done + echo "search done" +} + +logger -p info "${BASH_SOURCE[0]}" + +# get script owner name +user=`stat -c %U $0` + +if [ "$user" == `whoami` ]; then + # if script runned by owner - start main function + search_headsets +elif [ "`w -hs $user`" ]; then + # else if user session exist(to prevent running on system startup) - run script from user + machinectl shell $user@.host ${BASH_SOURCE[0]} +fi + |