SmackBook!
Posted by Corban Brook Sun, 28 May 2006 16:13:00 GMT
Many of you have seen the video of Erling Ellingsen’s SmackBook . Making use of the SMS to control Desktop Manager’s virtual desktop switched by hitting the MacBook left or right.
Below is everything you need to get this working on your MacBook Pro.
What you need
- AMSTracker (Universal Binary)
- BumpMotion (Ruby Script)
- Notify (Intel Binary)
- Patched Desktop Manager (Intel Binary)
AMSTracker
AMSTracker is a command-line program that retrieves acceleration data from the Sudden Motion Sensor in Apple notebook computers.
The author, Amit Singh, has in depth information on the Sudden Motion Sensor and some fun little programs that make use of it available on his website osxbook.com
BumpMotion
- Download BumpMotion.rb
First off I recommend using my new and improved ruby script for sensor readout processing.
BumpMotion.rb processes SMS readout and detects left of right bumps, triggering Desktop Manager’s Prev or Next Desktop methods.
The built in stabilizer finds the stable angle of the MacBook Pro and allows left or right bumps from any angle. This is helpful for when using the macbook on the couch or in bed when you dont have a flat surface available.
#!/usr/bin/ruby
threshold = 10 # degrees of motion required to trigger
stabilizer_speed = 6 # degrees of motion the stablizer can adust to each step without triggering
sensor_speed = 0.01 # update speed of the sensor in seconds. faster is better but uses more cpu.
seconds = (1 / sensor_speed).round
wait = 1 * seconds # seconds of stable motion before a triggering
stable = 0
stable_velocity = 0
f = IO.popen('./AMSTracker -s -u ' + sensor_speed.to_s, 'r')
while line = f.gets
next unless sensor = /(-?\d+)\s+(-?\d+)\s+(-?\d+)/.match(line)
velocity = sensor[1].to_i # -128 to +128
stable_velocity += stabilizer_speed if stable_velocity < velocity
stable_velocity -= stabilizer_speed if stable_velocity > velocity
difference = velocity - stable_velocity
stable += 1 if difference.abs < threshold
if difference.abs > threshold && stable > wait
stable = 0
direction = difference > 0 ? "Prev" : "Next"
`./notify SwitchTo#{direction}Workspace\n`
end
end
Notify: Remote control for Desktop Manager
- Download Notify (Mac Intel Binary)
- The following section is taken from Erling Ellingsen
This 15-line program lets you send random notifications to any running application.
#import <Foundation/Foundation.h>
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.
Desktop Manager
Download Patched Desktop Manager 0.5.3 (MacIntel Binary)
Lastly you will need a patched version of Desktop Manager to control your virtual desktops. The patched version allows us to hook into it with the notify program.
Desktop Manager is an excellent and free open source project by Richard Wareham, for adding virtual desktop support to OS X and it does it with style. Has 10 or so desktop switching transition effects that are sure to impress your friends. I beleive this program is the perfect companion to expose.
Execution
Now that you have all the tools its time to set it up.
- Start up Desktop Manager and configure it to your liking.
- Place the AMSTracker, BumpMotion.rb, and notify programs together in a directory.
- chmod u+x BumpMotion.rb and notify to make them executable.
- Run BumpMotion.rb:
./BumpMotion.rb
- Smack your Mac up!
View the source of BumpMotion.rb for furthur fine tuning and configuration.
Have fun!







