How to connect an Apple Bluetooth Keyboard to Ubuntu (Troubleshooting)

(0 votes, average 0 out of 5)

Note: This guide uses programs specific to Ubuntu 10.04 (Lucid Lynx) and newer. For older versions of Ubuntu, please refer to this Ubuntu Wiki page.

Sometimes the Ubuntu bluetooth stack can behave erratically and prevent you from connecting your Apple Bluetooth Keyboard (or other bluetooth device). The normal procedure for connecting your bluetooth keyboard involves the following steps:

First, make sure the bluetooth applet is running by looking for the bluetooth icon on your panel:

bluetooth-icon

If it is not running, press ALT+F2, enter bluetooth-applet in the dialog box, and click Run to start it:

bluetooth-applet-run

 

Second, click on the icon and select the "Set up new device..." link. This will bring up a window which gives you some instructions. Click Forward and then select your Apple Bluetooth Keyboard. Note: your keyboard must be turned on during this step:

bluetooth-applet

 

Proceed through the installer, entering the PIN that it gives you on the keyboard and hitting the Enter key when done. If all goes well, your keyboard should start working shortly thereafter. If it does not work, or you receive messages on the computer telling you to enter the PIN from the device, you will need to perform additional steps. Power off your keyboard and then open the Terminal program (gnome-terminal) and enter the following commands:

1
2
3
$ killall bluetooth-applet
$ sudo /etc/init.d/bluetooth restart
$ sudo hcitool dev

The last command should return output for your device, something like the following:

Devices:
	hci0	00:00:00:00:00:00

Once this is done, you will need to install a new package to allow you to connect to the device via the command line. To do so, enter the following command:

$ sudo apt-get install bluez-compat

Once this has completed, you will now have hidd program installed. At this point, turn on your keyboard and enter the following command. It will output the MAC Address of your keyboard, which you will need to copy and paste into the subsequent command, as seen below:

1
2
3
4
$ hcitool scan        
Scanning ...
	AA:BB:CC:DD:EE:FF	Apple Wireless Keyboard
$ sudo hidd --connect AA:BB:CC:DD:EE:FF

Give it a couple seconds and then try typing on your keyboard. Hopefully, it will now be connected and working. To automate this process so your keyboard will connect automatically when you start your computer, create a new file by running this command:

$ gedit ~/.keyboard.sh

Enter the following text, substituting AA:BB:CC:DD:EE:FF with the hardware ID you saw above. Finally, save the file.

1
2
3
4
5
6
7
8
9
10
11
#! /bin/bash
 
address="AA:BB:CC:DD:EE:FF"
 
while (sleep 1)
do
 connected=`sudo hidd --show` > /dev/null
 if [[ ! $connected =~ .*${address}.* ]] ; then
  sudo hidd --connect ${address} > /dev/null 2>&1
 fi
done

 

Then, create a new startup file:

$ sudo gedit /etc/init.d/keyboard

 

Paste the following into this file, which tells it to run the file that you just created at startup. Note, you must specify the entire path to your home directory. In this example, the username used is ubuntu:

1
2
3
4
#!/bin/sh
/home/ubuntu/.keyboard.sh &
 
exit 0


Now, set both files to be executable and then add the startup file to the list of startup programs:

1
2
3
$ sudo chmod +x /etc/init.d/keyboard
$ chmod +x ~/.keyboard.sh
$ sudo update-rc.d keyboard defaults

Restart your computer and your keyboard should work immediately! If not, please post a question here or at Ubuntu Forums for more troubleshooting.

Partner Links:
Last Updated on Wednesday, 27 October 2010 20:05  
Related Articles

» How to Show Filename in Title Bar in Emacs

Adding the following snippet into your .emacs file (typically located in your home directory) will cause the filename of the current buffer to appear in the title bar.  This is a quick fix that can make managing multiple emacs windows much easier. ;; Show filename in title bar(setq frame-title-format "%b - Emacs") 

» For Loops in PHP

To create a for loop in php, follow these simple steps:Set a counter variable to some initial value.Check to see if the conditional statement is true.Execute the code within the loop.Increment a counter at the end of each iteration through the loop.The following is pseudo php code for a for loop:123for(init counter; conditional statement; increment counter){ inner code;}As you can see, all of the above steps are taken care of within the for loop, making the syntax short and easy to...

» PHP - Read in a file

The following function demonstrates how to read in a local file with PHP. You must first use the function to open the file handle. This tells PHP where to look to find this file. After that, it is simply a matter of iterating over the file until there are no more lines. The function tests if it has reached the end of the file yet - returning true if it has and false if there is still more to be read. Once we know there is another line to be read in, reads in the line for us into a slot of...