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

» Change Default Access URL of phpMyAdmin

By default, phpMyAdmin installs its web interface to a well-known location, like yourhost.com/phpMyAdmin. In order to make the phpMyAdmin installation more secure, it is a good idea to change this to a different, unique name. In order to do so, open the apache.conf file in the phpMyAdmin's configuration directory. On many Linux servers, this file is located in /etc/phpmyadmin/. At the top of apache.conf, look for the following line:123# phpMyAdmin default Apache configuration Alias...

» How to Make Fonts on Ubuntu Linux Look Crisp Like on Microsoft Windows

Have you noticed that fonts on Linux distributions (like Ubuntu) appear fuzzy compared to Microsoft Windows? This is because Ubuntu is using a font display technique called "hinting" which draws the fonts more accurately but can appear blurry to users used to Windows. Below is an example of the difference between Polished Fonts (the Ubuntu default) and Sharp Fonts (the Windows default):Thanks to for the screenshot.InstallationIt is possible to make Ubuntu (and other Linux distributions) render...

» Mirror Website Directory Over FTP

You can easily mirror the contents of a directory over FTP using the lftp program on Linux. To connect, create a configuration file for lftp that specifies the credentials for the ftp server, the directory on the remote ftp server that you want to download files from, and where you want to place them on the local machine:123456set ftp:anon-user "ftpusername"set ftp:anon-pass "ftppassword"set ftp:ssl-allow noopen remote-ftp-server.commirror -c /remote/directory/...