This is the follow-up on my Asus EEE PC configuration. Next on my TODO list was to make the webcam work, and as Ben Armstrong had pointed it worked fairly well, proving to be a non-issue.
After that, I decided it would be a good thing if the presence of my bluetooth-enabled cellphone were tested, so that if I walk away from the PC, it called xscreensaver -lock. After some googling, I found a tool that did just that: BlueProximity. It really seemed a good idea, except that my cellphone (a Palm Treo 650) kept warning me about a connection going on, which was quite unpleasant. This happens because BlueProximity tests the RSSI of a bluetooth connection… Beautiful, but a little overkill for what I wanted: I just wanted to know if it is there or not.
First I tested the bluetooth discovery with hcitool scan, but for that I would have to keep my cellphone Discovery On, which is not a smart thing to do… So I tested other things, and found out that hcitool name XX:XX:XX:XX:XX:XX only returned the name of my cellphone if it were around. So that was what I used. This is treo-presence.sh script:
#!/bin/bash TREO='XX:XX:XX:XX:XX:XX' NAME='name_of_my_cellphone' CMD="/usr/bin/hcitool name $TREO" if [ "`$CMD`" = "$NAME" ]; then exit 1 fi exit 0
It returns 0 or 1 if the TREO device is absent or present, respectively. I use it from the following cron script:
#!/bin/bash /usr/bin/w | /bin/grep $LOGNAME > /dev/null 2>&1 if [ $? -ne 0 ]; then # Running user is not logged in exit 1 fi CMD="/usr/local/bin/treo-presence.sh" LOCK_CMD="/usr/bin/xscreensaver-command -lock" FILE="/tmp/no-treo-lock.txt" TMPFILE=`/bin/tempfile` /bin/touch $FILE /usr/bin/tail -2 $FILE > $TMPFILE $CMD; echo $? >> $TMPFILE /bin/mv $TMPFILE $FILE /bin/rm -f $TMPFILE for line in `cat $FILE`; do if [ "$line" = "1" ]; then exit 1 fi done # Got here: all 3 lines are not 1 $LOCK_CMD > /dev/null 2>&1 exit 0
This is run from the user crontab file every minute, recording the last 3 runs in a file in /tmp. If all 3 runs indicates the absence of my cellphone, xscreensaver -lock is called. Simple enough and doesn’t give me connection warnings in my Treo.
Other approaches are surely possible. Also, I am not sure treo-presence.sh would work for other devices… This is just what works for me…