HOWTO: A quick way to connect to your bluetooth headset

Hi!

I think working with a bluetooth Headset is pretty annoying with linux. There's no way to quickly connect to your headset and get a visual feedback that the connection works. So here's a solution for that.

A small script which enables the connection and shows a popup via libnotify on your desktop. It will look like like this.

Please note: This won't help you to solve problems with your BT headset. You need a already configured bluetooth setup for this how-to. So before trying to do this how-to, make sure your setup is OK. For help how to do this, look e.g. here

https://help.ubuntu.com/community/BluetoothSkype

To get this working make sure libnotify-bin is installed on your system

Code:


sudo apt-get install libnotify-bin

After that, you create the script

Code:


sudo gedit /usr/local/bin/headsetconnect

and paste this content

Code:


#!/bin/bash

# HeadsetConnect 1.0 connect by Chrissss
# you need libnotify-bin to run this script

# Enter the bluetooth address of your headset here
MAC=xx:xx:xx:xx:xx:xx

# Localisation
TITLE="Bluetooth"
CONNECTED="Connection to headset established."
ALLREADYCONNECTED="Connection to headset already exists."
FAILED="Connection to headset failed!"
BTLOGO=/usr/share/icons/gnome/48x48/stock/io/stock_bluetooth.png

# Now the magic
PID=`pidof btsco`

if [ ! $PID ]
then
  btsco -v -s -f $MAC
  if [ -e /tmp/bt_headset_connected ]
  then
    notify-send -i $BTLOGO -t 3000 "$TITLE" "$CONNECTED"
  else
    notify-send -i gtk-dialog-warning -t 3000 "$TITLE" "$FAILED"
    killall btsco
  fi
else
  notify-send  -u critical -i gtk-dialog-info -t 3000 "$TITLE" "$ALLREADYCONNEC
fi


Make sure to replace the "xx"s with the correct BT address of your headset. After that make the script executable

Code:


sudo chmod 755 /usr/local/bin/headsetconnect

Well, you're done. Call

Code:


headsetconnect

out of a terminal window, or even better, put a starter inside the gnome bar.

CU
Christoph