small bluetooth script..

Posted: January 17, 2015 in scripts
Tags: , , ,

     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:

./ con

to connect and

./ 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/ con"
    m:0x40 + c:69
    Mod4 + F3 
#headset dis
"~/./.scripts/ dis"
    m:0x40 + c:70
    Mod4 + F4 

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

     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

Comments are closed.