Way back I did a quick tutorial showing how to pair the Apple Wireless Keyboard with Ubuntu 9.1. Yikes the releases go by fast. That post had some serious loopholes and did not allow for automatic pairing on start up and after sleep mode. This new method includes all of this, but is slightly more complicated, although more solid than my previous post. First, upgrade/install your machine to Ubuntu 11.04. Everyone (including myself) seems to have the most luck with this release. This solution is also great as it does not depend on non existant Bluetooth files in earlier packages.
Start by making a copy of your Bluetooth script located in /var/lib/bluetooth
Now remove all Bluetooth packages:
sudo apt-get purge bluez blueman gnome-bluetooth bluez-utils
Now install Blueman and Bluez from source. You can look these packages up online. Compile (you have to do this for both packages separately of course) by unzipping these packages and typing the usual:
sudo make install
Copy your old Bluetooth script to /etc/init.d (with premissions 755)
Then add Blueman to your startup programs and reboot. The keyboard should now auto pair on sleep and boot. Pretty Cool.