dotfiles

My personal shell configs and stuff
git clone git://git.alex.balgavy.eu/dotfiles.git
Log | Files | Refs | Submodules | README | LICENSE

smack.pl (2251B)


      1 #!/usr/bin/perl -w
      2 
      3 # Smackbook for Yosemite Spaces
      4 # ============================
      5 # Updated for OS X Yosemite by Steven Bock
      6 # stevenbockster@gmail.com
      7 # bocksg@plu.edu
      8 # November 4th, 2014
      9 #
     10 # Originally rebuilt by Jason Shen for OS X Leopard
     11 # iamreal2@hotmail.com
     12 # 16 Nov 2007
     13 #
     14 # Based on Brian Jepson's Smaxpose2.command
     15 #   http://www.jepstone.net/blog/2006/05/25/expose-smackbook-pro-style/
     16 # Which is
     17 # Based on Erling Ellingsen's SmackBook Pro scripts:
     18 #   http://blog.medallia.com/2006/05/smacbook_pro.html
     19 #
     20 # This program is free software; you can redistribute it and/or
     21 # modify it under the terms of the GNU General Public License
     22 # as published by the Free Software Foundation; either version 2
     23 # of the License, or (at your option) any later version.
     24 #
     25 # This program is distributed in the hope that it will be useful,
     26 # but WITHOUT ANY WARRANTY; without even the implied warranty of
     27 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     28 # GNU General Public License for more details.
     29 
     30 # =====================================================================
     31 
     32 # USAGE:
     33 #
     34 # Save this script into a file called smackleopard.command, and make
     35 # it executable with the Terminal command:
     36 #
     37 #   chmod +x smackleopard.command
     38 #
     39 # Then, run it from the Terminal or double-click it in the Finder.
     40 
     41 use strict;
     42 my $stable = 0;
     43 
     44 # Get AMSTracker from Amit Singh's site:
     45 # http://www.osxbook.com/software/sms/amstracker/
     46 # and put AMSTracker in same directory as smackleopard.command
     47 #
     48 open F,"./AMSTracker -s -u0.01 |";
     49 while(<F>) {
     50     my @a = /(-?\d+)/g;
     51     print, next if @a != 3;
     52 
     53     # we get a signed short written as two unsigned bytes
     54     $a[0] += 256 if $a[0] < 0;
     55     my $x = $a[1]*256 + $a[0];
     56 
     57     if(abs($x) < 20) {
     58 	$stable++;
     59     }
     60 
     61     # you can adjust sensitivity here
     62     # original file uses 30. 20 is better for me.
     63     if(abs($x) > 10 && $stable > 10 ) {
     64 	$stable = 0;
     65 
     66 	# check if it is LEFT or RIGHT tap
     67 	# I use ^ArrowKeys for Leopard Spaces to switch.
     68 	if ($x < 0) {
     69         	`osascript -e 'tell application \"System Events\" to keystroke (ASCII character 29) using control down'`
     70 	} else {
     71 		`osascript -e 'tell application \"System Events\" to keystroke (ASCII character 28) using control down'`
     72 	}
     73     }
     74 }