Filed under: Software, Odds and ends
Found Footage: Smack your MacBook Pro
This video shows a clever use of the Apple sudden motion sensor. Simply tap the side of your MacBook and the desktop switches. Sadly, the URL at the beginning of the video is password protected. Here's hoping somone releases the code.

![TUAW [Cafepress]](http://www.blogsmithmedia.com/www.tuaw.com/media/tuaw-cafepress-promo.png)


Reader Comments (Page 1 of 2)
kevin said 1:35PM on 5-24-2006
this was found via digg, by the way.
Reply
Scott McNulty said 1:36PM on 5-24-2006
It actually wasn't, kevin.
If I found it via digg I would have said so, but thanks anyway! :)
Reply
andy said 1:49PM on 5-24-2006
cant be healthy but it waaayyy cool, macbook typewritter.
Reply
marc cardwell said 2:16PM on 5-24-2006
ok, what is the liquid app thing he moves right then back left? its just the kind of useless thing i'd like to have.
Reply
moose said 2:39PM on 5-24-2006
It's Desktop Manager - basically, the same as "virtual desktops" on Unix.
BTW, I'm working on a generic "smack" code now. I'll release it when done; I'm thinking of "smack pinball" or something.
Reply
Bwhit said 2:54PM on 5-24-2006
How about Smack the Weasel?
Reply
Adrian vG said 3:33PM on 5-24-2006
SmackBook PRO :)
So does the desktop manager support the sudden motion sensor?
Reply
Lars said 3:58PM on 5-24-2006
I must say it looks rather fake. The screen seems to be superimposed on it. Also, from what I know, the motion sensor doesn't erm, sense this kind of motion.
Ah well.
Reply
Nick Postagulous said 4:14PM on 5-24-2006
Heck, I know how to fake this. And the camera shake does look fake. Keeps the exact same perspective while the image moves around slightly. No tilt, just lil micro pans. But, whatever, not something I need. How about keys that do that if it's such a brilliant idea.
Reply
Peter said 4:20PM on 5-24-2006
It also seems as if the screen changes a instant before his hand comes in contact with the screen.
Reply
Jason Piper said 4:37PM on 5-24-2006
Ok... first get AMSTracker (http://www.osxbook.com/software/sms/amstracker/). I ganked this first from elsewhere as a rough draft. I use YouControl Desktop to control desktop switching (shift+control+option+command+f). Get this script (http://www.no-rulz.net/screenswitch.py). Put AMS and the screenswitch.py in the same folder and run this ./AMSTracker -u 0.1 -s | python screenswitch.py
With any luck it should run
Reply
Jeduthun said 4:38PM on 5-24-2006
It is a fake. Look at the image I've just uploaded:
http://rapidshare.de/files/21295708/fake.jpg.html
The screen changes BEFORE the guy's fingers hit the Mac.
Reply
Amit Ahluwalia said 5:41PM on 5-24-2006
Just tried AMSTracker and when you run the command in terminal the screen just keeps flipping until I hit cmd+c to make it stop. Anyone else get it to work?
Reply
Aitor Garcia said 6:23PM on 5-24-2006
The script works ...almost well. You must modify the line:
THRESHOLD = 8 # lower numbers makes this more sensitive
A value from 7 to 10 seems to be more useful than the default 3.
Execute only "./AMSTracker -u 0.1 -s" without the piped process to see the reaction of the AMS and the change the script accordingly
Reply
Victor Agreda, Jr. said 7:05PM on 5-24-2006
Uh, couldn't you just trigger a desktop switch via built-in microphone? That's right, the motion sensor doesn't double as an earthquake alarm. It can't detect minute vibrations like a few fingers smacking the screen (pounding on the body, maybe).
But smacking the side would easily spike the audio input.
Reply
Andrew Harrison said 7:08PM on 5-24-2006
first off, Jeduthun, ya jackass, clearly that's his hand on the way off the screen after tapping it. watch it again.
and also,
he's released the code
http://blog.medallia.com/2006/05/smacbook_pro.html
So it doesn't get lost when Digg grabs hold:
---- START CODE
Desktop Manager patch
First, you'll need to be able to control Desktop Manager from outside. Cocoa has a nice class called NSDistributedNotificationCenter which can handle simple message passing between applications. DM uses a notification center internally to send "next desktop", "previous desktop" commands to itself, so the patch just replaces the normal version with the distributed version. I added the following to WorkspaceController.m, inside the init method:
[[NSDistributedNotificationCenter defaultCenter] addObserver: self
selector: @selector(selectNextWorkspace)
name: NOTIFICATION_NEXTWORKSPACE
object: nil
];
[[NSDistributedNotificationCenter defaultCenter] addObserver: self
selector: @selector(selectPreviousWorkspace)
name: NOTIFICATION_PREVWORKSPACE
object: nil
];
To control all the windows in the system, an application needs to have access to the CGSUniversalConnection; only one application can have that at a given time, and the Dock tends to win the battle. Desktop Manager sneakily uses mach_inject to inject its own code into the Dock application. There's still no x86 version of the sweet, sweet mach_inject library (Wolf! Help us!), so not all the Desktop Manager features will not work on Intel.
Reading the sensor
For the actual sensor reading, I used amstracker by Amit Singh. He does not allow redistribution, so you'll have to get it directly from the source.
notify: Remote control for Desktop Manager
This 15-line program lets you send random notifications to any running application.
#import
int main (int argc, const char * argv[]) {
[[NSAutoreleasePool alloc] init];
if(argc != 2) {
NSLog(@"Use: %s notification-name", argv[0]);
return 1;
}
[[NSDistributedNotificationCenter defaultCenter]
postNotificationName: [NSString stringWithCString: argv[1]]
object: nil];
return 0;
}
Compile it with gcc -framework Foundation -o notify notify.m, then call it with ./notify SwitchToNextWorkspace.
Actual motion interpreter
You can do arbitrarily fancy stuff here; this 10-line Perl script just checks to see if the horizontal acceleration exceeds some threshold in either direction, and calls the notify program.
use strict;
my $stable;
open F,"./AMSTracker -s -u0.01 |";
while() {
my @a = /(-?d+)/g;
print, next if @a != 3;
# we get a signed short written as two unsigned bytes
$a[0] += 256 if $a[0] < 0;
my $x = $a[1]*256 + $a[0];
if(abs($x) < 20) {
$stable++;
}
if(abs($x) > 30 && $stable > 30) {
$stable = 0;
my $foo = $x < 0 ? 'Prev' : 'Next';
system "./notify SwitchTo${foo}Workspacen";
}
}
---- END CODE
he's also got it as a zip
Reply
Mart said 7:38PM on 5-24-2006
Well I got it working. You have to read the instructions, guys. Also you have to use a PPC mac to compile DesktopManager - mach_inject doesn't compile on intel. Fun but not super usable...
Reply
michel said 9:02PM on 5-24-2006
wonderful.
but I'm disappointed there are no more mach inject for intel. it was a terrific idea (and a very dangerous one ! my dear hobbit) to improve DM.
the last comment is wonderful. source code, explanations and all the references. many thanks mr Harrison!
Reply
Jeduthun said 10:27PM on 5-24-2006
Andrew, do you feel compelled to insult other people to prove them that they are wrong?
You must feel very insecure, po' boy.
Reply
DVDLV said 12:40AM on 5-25-2006
Excellent !
Reply