Braindead simple Bluetooth tricks

Jealous of the Mac-freaks and all the cool tricks they can do with their Bluetooth cellphones, like locking their computer automatically when they walk away?

I spent a few minutes today hacking around and came up with a quick proof-of-concept script for something thats been bouncing around in my head for awhile:

!/bin/bash

DELAY=”20″ BD_ADDR=”FF:FF:FF:FF:FF:FF” LOCK_CMD=”xscreensaver-command -lock” while true; do (sudo l2ping -s 1 -c 1 $BD_ADDR > /dev/null 2>&1 ) || $LOCK_CMD sleep $DELAY done

It periodically pings your Bluetooth phone (replace BD_ADDR with the particular BD Address of your phone). When the ping fails (when you walk out of range), it can lock your screen, pause XMMS, etc. Not bad for 5 lines of Bash script.

Now I’ve just got to beef it up a bit, add some more options. If I’ve got the time, I’ll turn it into a Python Gnome applet so you can throw it in a toolbar.

Related posts:

Tags: , ,

  1. Remy’s avatar

    Dang…I think that’d be awesome. Pardon me for asking, I guess, but not being into Linux as of just yet (I just downloaded Debian, geez!) I can’t think of any way to make this applicable to a PC with Windows XP. Do you have any suggestions? Thanks!

  2. P L McMahon’s avatar

    I wrote a very basic Python applet that will monitor a Bluetooth device using the Gnome Bluetooth subsystem. It uses the l2ping command demonstrated here.

    Locking your Gnome session via Bluetooth

    Thanks for the idea Chris, and I hope others find this useful.

  3. robert’s avatar

    wot the hell does dat mean i don understand pleese explain it to me i wan to do it

  4. Josh’s avatar

    hi there, i like the /dev/null 2>&1 ) || $LOCK_CMD sleep $DELAY done>>>>>

    script alot, being a bit of a cmd novice how would i run this?