#!/usr/bin/perl -w # Smackbook for Leopard Spaces # ============================ # Last modified by Jason Shen # iamreal2@hotmail.com # 16 Nov 2007 # # Based on Brian Jepson's Smaxpose2.command # http://www.jepstone.net/blog/2006/05/25/expose-smackbook-pro-style/ # Which is # Based on Erling Ellingsen's SmackBook Pro scripts: # http://blog.medallia.com/2006/05/smacbook_pro.html # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # USAGE: # # Save this script into a file called smackleopard.command, and make # it executable with the Terminal command: # # chmod +x smackleopard.command # # Then, run it from the Terminal or double-click it in the Finder. use strict; my $switch = 0; my $prevX = 0; # Get AMSTracker from Amit Singh's site: # http://www.osxbook.com/software/sms/amstracker/ # and put AMSTracker in same directory as smackleopard.command # open F,"./AMSTracker -s -u0.015 |"; #using a slower update time save CPU cycles #this is 5% cpu usage on a 2GHz dual core #but less frequent refreshes cause less predictable #behavior 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]; my $change = abs($prevX) - abs($x); #check for bumb $prevX = $x; #retain previous X position if($switch > 0) { #reset switching capability $switch--; } # you can adjust sensitivity here. 30 is a light tap # 100 is a generous bump, 10 is remarkable stable but a toddler could switch spaces if(abs($change) > 25 && $switch == 0){ #if bump is bigger than desired value then switch $switch = 10; #approx time before next switch allowed # check if it is LEFT or RIGHT tap # I use ^ArrowKeys for Leopard Spaces to switch. if ($x < 0) { `osascript -e 'tell application \"System Events\" to keystroke (ASCII character 29) using control down'` } else { `osascript -e 'tell application \"System Events\" to keystroke (ASCII character 28) using control down'` } } }