Article / 27th Feb 2007

Bluetooth and Computer Locking

Occasionally, I'll think of something so good I have to rush and implement it on the spot. Last week I had one of those moments; Martin had mentioned to me that he'd bought a Wireless PC Lock, which is a little thing you plug into the USB port, and which locks your computer when you walk away with its 'key' transmitter.

Being quite cheap, and not wanting to wait for any sort of delivery, it occurred to me that the same thing could be achived with Bluetooth; as long as a device was broadcasting its presence, you could detect when it came into bluetooth range and went out of it again. Having a nice bluetooth dongle, I installed python-bluez, and set to work.

Shortly afterwards, I had a nice scanning script that continuosly probed the local area, matched the resulting MAC addresses to an internal list, and then ran lock and unlock scripts. A few minutes more, and I tied in amaroK, Kopete, the screensaver, and even DPMS (display power management).

Now, I can walk out of my room, and a few seconds later the computer will lock itself, turn off the screen, pause any music and set my IM status to Away. Walk back in, and the computer unlocks, I get set to Available, and the display turns back on.

It's like living in the future - the feeling of walking into a room and having the computer recognise your presence is wonderful.

There are, of course, a few problems. This only works, currently, with devices that broadcast their presence. For me, this is fine, since my n800 will happily sit in "visible" mode. Many phones, however, only support this for finite periods of time, and in general some people don't like to have it on.

I'm looking into some sort of solution involving pairing; in the meantime, you can find an initial copy of the script here.