Smacbook Pro

Everyone is all abuzz with news of the SmacBook Pro hack. Very very cool.

I wanted to have a play with it, but Amit’s AMSTracker doesn’t appear to work on my 15″ MBP.

Fortunately, someone else hacked together a little SMS reader that does work on Intel. Unfortunately, it is a different format than what AMS emits and it only reads once and spews. Fortunately, I know my way around C and fixed it (tarball of source).

The SmacBook Pro hack uses a perl script to interpret the output of AMSTracker. Since the output is different for motion and the script is so trivial, I rewrote it in Python and used PyObjC to send the notification directly from the script. Requires Python 2.4 (or copy the subprocess module from 2.4) and PyObjC:

#! /usr/bin/python
from Foundation import *
import subprocess
import time

# assumes the motion executable is named 'motion-bin' and is CWD
pipe = subprocess.Popen(["./motion-bin"], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
stdout = pipe.stdout

stable = 0
while 1:
    line = stdout.readline()
    x = int(line.split()[0])

    if abs(x) < 20:
        stable = stable + 1

    if (abs(x) > 30) and (stable > 30):
        stable = 0
        if x < 0:
            notificationName = "SwitchToPrevWorkspace"
        else:
            notificationName = "SwitchToNextWorkspace"
        
        print notificationName
        NSDistributedNotificationCenter.defaultCenter().postNotificationName_object_(notificationName, None)

Running the above script will print "SwitchToPrevWorkspace/SwitchToNextWorkspace" whenever you smack your machine. If the modified version of Desktop Manager is running -- it was trivial to make it build universal with the additional notification observer -- then it'll switch desktops with every smack. You'll want to configure Desktop Manager to have one row of desktops and for the animation to be a slide between desktops.

It actually works quite well, though it'll occasionally slide the wrong direction. Blame the math (or lack thereof).

And, of course, the above demonstrates how trivial it would be to make various physical gestures control other aspects of your machine. Since I don't actually use multiple desktops, I replaced the notification stuff with a call out to applescript to play the next track in iTunes.

I can't take any credit for any of this. I just glued together a slightly different set of parts to make it all work on my MacBook Pro. While it works really well, it is far from totally useful. It busy-reads from the motion sensor, spewing new values every few milliseconds. As a result, leaving this thing running eats battery life while chewing up a bunch of CPU.

Fun toy, though.



5 Responses to “Smacbook Pro”

  1. Victor says:

    Cool post Bill.

    Looks like other folks are doing some stuff with AMSTracker

    http://blog.medallia.com/2006/05/smacbook_pro.html

  2. bbum says:

    Yeah — it just didn’t work at all for me, regardless of the preferences I wrote. Punt. Tried motion. It worked.

    Not an original thought in my head on this one — I just used a different glue. :-)

    Thanks for putting together the original instructions.

  3. Victor says:

    Ah, update to my comments. I am _not_ the person who did up the instructions, just one of the peons that follow the bbum chronicles and wanted to link up the two chunks of work.

    I think it is because I put the http://blog.medallia.com link in the ‘website’ part of the comment form. Opps.

    At the next preso you do, I wanna see you smack your MBP to advance the Keynote slide ;-)

  4. bbum says:

    Heh. OK — my confusion reins supreme.

    Yes — my timing sucks. I did a preso Wednesday and smack-to-advance would have been awesome.

  5. leeg says:

    I wonder how long it’ll be until we see the “I smacked the bejeezus out of my MacBook and now it’s broken, Apple suck!” class-action suit…

Leave a Reply

Line and paragraph breaks automatic.
XHTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>