Problem and Background
I'm often annoyed by small inefficiences. Typically, these are manual tasks which a machine should be doing for me. One inefficiency that's bothered me for a while is coordinating my IM status (away vs available) with my presence in the office.
Adium is my IM client. It can detect keyboard and mouse movement and automatically set my status as away after a couple minutes of inactivity. Unfortunately, it can't tell when I'm working on the whiteboard across the room. In that case, I might not have typed for a while, but I'm still available.
I tried using software like HomeZone or MarcoPolo to make my cell phone a proximity sensor. I set them up to detect the presence of my phone's bluetooth connection. When it sensed the bluetooth connection disappear, it set me as away. When the connection reappeared, it set my status to available. Unfortunately, bluetooth is too strong a signal for my house's floorplan. When I'm in the dining room eating lunch or in the bathroom taking a shower, the bluetooth signal from my phone is still strong in my office. I have to walk all the way across the house before MarcoPolo tells Adium that I'm away.
I searched for USB proximity sensors, but couldn't find anything decent. Everything was too expensive or too complicated to set up.
Solution
For a project I'm working on, I needed a small webcam. I bought a $40 Logitech QuickCam E3500 at Walmart. The box only claims compatibility with Windows, but it works fine with my Mac. This morning, I realized that it could become a motion detector and solve my IM status problem. Here's what I did (after plugging in the camera):
- Download, install and run Periscope (50 hour free trial, then $25 to purchase)
- Under the "Capture" tab, click the boxes next to "Camera sees movement" and "watch the entire camera"
- In the upper-left corner of the live image, adjust the slider so that it points at the second box from the left. This makes the camera quite sensitive to movement. You might get better behavior with a different setting.
- In Periscopes preferences, under General, uncheck the box "Flash camera and play sound when taking a photo". Under Review, make sure that the photos folder is set to "~/Pictures/Periscope"
- Download the file proximity.pl (part of a Github project)
- Open the Terminal application (or iTerm or whatever you use)
- Type "perl proximity.pl" ("proximity.pl" should be the full path to the downloaded file)
When you stop moving for 30 seconds, your Adium status will be set to away. Once you've been moving again for 5 seconds, your Adium status returns to available.
Future Improvements
It would be great if this kind of proximity detection was built directly into the Periscope software. Since it's already awake and taking the pictures, it would be pretty easy for it to execute scripts when it detects someone entering or leaving the room. I'll email the developer about the idea.
Instead of hard-coding the behaviors when I enter or leave the room, it would be better for the script to take the name of two other scripts. One script would be executed each time I arrive in the room. The other would be run each time I leave the room. That way, others can use the script with their preferred IM client or for some other use that I haven't thought of yet.
Is there value in having the timing constants (30 seconds and 5 seconds) configurable on the command line?
You can clone the Git repository at git://github.com/mndrix/proximity.git As with all open source projects on Github, feel free to fork this project. If I see patches that I like, I'll apply them to my repository.