Change between workspaces using HP 2140 accelerometer

HP mini 2140 netbook comes with an ST Microeletronics accelerometer and under linux kernel 2.6.27 we found a driver that supports it (LIS3LV02Dx).
With wmctrl and some scripting we can toggle between workspaces when we tilt the machine left or right. This is a useless script but it has some fun :)

First you need to install wmctrl
sudo apt-get install wmctrlbash shell script - Download#!/bin/bash

COUNTER=0

while [ $COUNTER -le 100 ]; do
    sleep 0.5
    POS=`cat /sys/devices/platform/lis3lv02d/position | awk -F "(" '{print$2}' | awk -F , '{print$1}'`
    echo $POS
        if [ $POS -ge 12 ]; then
            wmctrl -o 1024,0
        elif [ $POS -le -12 ]; then
            wmctrl -o 0,0
        fi
    COUNTER=$(( $COUNTER + 1 ))
done
UPDATE Sep 8, 2009: an approach in python - Download#!/usr/bin/python
import time
import os
cnt=0
while cnt <= 100:
    time.sleep(0.5)
    f = open ('/sys/devices/platform/lis3lv02d/position','r')
    data = f.read()
    ar = data.split(',')
    results = ar[0].replace('(',''), ar[1], ar[2].replace(')','')
    print results
    if (ar[0].replace('(','') >= '12'):
        os.system('wmctrl -o 1024,0')
    elif (ar[1] <= '-12'):
        os.system('wmctrl -o 0,0')
    f.close()
    cnt += 1
Note: Scripts will work when System/Preferences/Appearance/Visual Effects is set to Normal or Extra.