January 17

small bluetooth script..

     This script makes use of keyboard shortcuts to connect and disconnect a bluetooth headset. It makes use of xbindkeys (example here). Running the command directly in the terminal looks like:

./btheadset.sh con

to connect and

./btheadset.sh dis

to disconnect.
     When updating the xbindkeys configurtion file, those are the inputs to the command. I’ve used the logo+F3 and logo+F4 keys for each, so that portion of the configurtion file looks like:

#headset con
"~/./.scripts/btheadset.sh con"
    m:0x40 + c:69
    Mod4 + F3 
#headset dis
"~/./.scripts/btheadset.sh dis"
    m:0x40 + c:70
    Mod4 + F4 

note: ~/./.scripts/btheadset.sh could also be ~/.scripts/btheadset.sh

     Here’s the script part:

##  Script to connect and disconnect bluetooth headset 
btcon="bt-audio -c 00:1E:7C:01:F9:BF"
btdis="bt-audio -d 00:1E:7C:01:F9:BF"
case $1 in
        con)    $btcon
                kdialog --passivepopup 'BT Headset Connected' 3
        dis)    $btdis
                kdialog --passivepopup 'BT Headset Disconnected' 3

     In the above script I’ve used kdialog to produce a 3 second notification on the KDE desktop environment. Remove that line if you don’t use kde. Also, replace the MAC address with that of the device found using the command:

bt-device -l

Tags: , , ,

Posted January 17, 2015 by wm in category scripts