quarta-feira, 9 de setembro de 2009

Use your cellphone bluetooth to set your status on IM's

meta: Another tip from my spare time on my vacations. :)

The idea is simple, put your cellphone on your pocket and set the status of your IM's as you walk away from your PC. Easy like that. The basic concept is to write a shell script that checks if your cellphone is around using the bluetooth protocol and put it on the crontab. If your cellphone is not around, the script sets away on both Xchat and Pidgin and so on. Well, talk is cheap...

First of all, turn you cellphone bluetooth on, then check its MAC address with hcitool:
otubo@phoenix ~ $ hcitool scan
Scanning ...
00:1F:DE:4A:AD:C1 otubophone

After, write a simple shell script that tries to match the name of the device with the MAC address. If the cellphone is not around, then set the status of your Xchat and Pidgin to "Away From Keyboard" and lock the screen, otherwise, set the status as "Available". (I didn't unlocked the screen for security reasons, I do prefer typing the password instead)


CMD=`/usr/bin/hcitool name $MAC`

if [[ $CMD != $NAME ]]; then
xchat --existing --command="ALLSERV away";
xchat --existing --command="ALLSERV nick otubo[AFK]";
purple-remote "setstatus?status=away&message=Away From Keyboard";
gnome-screensaver-command --lock;
xchat --existing --command="ALLSERV back";
xchat --existing --command="ALLSERV nick otubo";
purple-remote "setstatus?status=available&message=Available";

Make it executable:
chmod +x /path/to/your/script.sh

And finally, put your shell script on the crontab to check it every minute:
* * * * * /path/to/your/script.sh

Actually, all this stuff is more cool than really useful. Just a weekend project I wanna share :P
Postar um comentário