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.

comments
Very neat idea!
Too bad I don't have any bluetooth devices, would have tried it right away!
Did you use dcop to control amarok\kopete?
Yes, I used dcop, it rules for this kind of thing. Yet another reason I love KDE :)
What do you use to lock and unlock your screen?
I used DCOP for that as well - kscreensaveer has an interface like everything else. Specifically:
dcop amarok player pause
dcop kaffeine KaffeineIface pause
dcop kopete KopeteIface setAway
dcop konversation irc setAway "more than 10m away"
dcop kdesktop KScreensaverIface lock
xset dpms force off
Hi there,
I am not familiar with how to use these kinds of scripts. My distro is Mandriva 2008.0 with KDE 3.5.7. What should I do to get the script working and for example pause amarok when I am walking away from my pc?
Thanks in advance for any help.
Best regards,
Jethro
Hi
To set up the script, download it, name it something like lock.py then open it in a text editor.
Change the bluetooth address to your phone/other discoverable device's address (the line that says DEVICE)
Change the lock command to something like dcop kdesktop KScreensaverIface lock
Change the unlock command to kdesktop KScreensaverIface quit
For multiple commands, like locking and pausing amarok it would be (I *think*)
dcop kdesktop KScreensaverIface lock && dcop amarok player pause for locking
dcop kdesktop KScreensaverIface quit && dcop amarok player play for unlocking
This is assuming you're on KDE. Feel free to email me at voltagex+aera@voltagex.org - although this email address may be down at the moment, and leave the +aera in for my spam filtering purposes :D