View Full Version : [ubuntu] Need a script to restart bluetooth service.

February 26th, 2009, 03:30 PM

I am currently running Ubuntu 8.04 and have a little knowledge in linux. I would like to create a launcher or a small script to restart the bluetooth service. When I hit the Fn+2 key it shuts of the bluetooth signal but doesn't fully restart the service or maybe it just doesn't recreate the connection to my bluetooth device. When I execute this command: sudo /etc/init.d/bluetooth it does. I can do this but I would rather make a clickable icon to do this for the users I have.

Please help!

March 1st, 2009, 04:27 PM
I know that the command

sudo /etc/init.d/servicename restart

will restart most services. I tested this out with the bluetooth service, and it seemed to work. So try out

sudo /etc/init.d/bluetooth restart

Hope this helps!

March 1st, 2009, 05:06 PM
It is possible to run a script just by pressing the button or have it run because of some other hardware event. Unfortunately the details of this are beyond my experience at this time. I do know it is tied in with the files in /etc/acpi. These are scripts that run on events like open/close laptop lid, toggle wifi or bluetooth button, etc. Hope this info helps you find an answer.

March 3rd, 2009, 07:18 AM
Hey, I wrote a GUI script for it :)

It required zenity package so please install if you don't have it. You can add this script to desktop or panel as well.

Download it, then
% chmod +x bluezen

On a side note, if you found the information box is annoying then remove this line " zenity --info --text "$STATUS" "

Idyllic Tux


# Comment out if your is toshiba laptop

SWITCH=$(zenity --list --text "Please Select Bluetooth Option:" --radiolist --column " * " --column "Option" TRUE "On" FALSE "Off" FALSE "Restart" FALSE "Status");
echo $SWITCH

if [ $SWITCH = "On" ]; then
# Comment out if your is toshiba laptop
# TOSHSET="on"
bluetooth-applet &
elif [ $SWITCH = "Off" ]; then
PID=$(pidof bluetooth-applet)
kill $PID
elif [ $SWITCH = "Restart" ]; then
# Comment out if your is toshiba laptop
# TOSHSET="on"
PID=$(pidof bluetooth-applet)
kill $PID
bluetooth-applet &
#"Unknown parameter. Quitting."

## Initialization
STATUS=`gksudo /etc/init.d/bluetooth $SWITCH`
zenity --info --text "$STATUS"
# Comment out if your is toshiba laptop
# gksudo toshset -bluetooth $TOSHSET