Exposé, SmackBook Pro style
Erling Ellingsen has written an awesome toolset for smacking your Mac to switch desktops. Here’s a modified version for those of us who are using Exposé instead of virtual desktops. You can smack the MacBook Pro to trigger Exposé. Because all I’m doing is firing up Exposé, you only need this script and Amit Singh’s AMSTracker.
Update: A slightly simpler version is available here. The only difference is that it lets you put AMSTracker and smaxpose.command in the same directory rather than having to put AMSTracker in your PATH.
Note that if you are using something other than F9 for Expose, you’ll need to change the key code from 101 to whatever works.
May 25th, 2006 at 9:28 am
I keep getting a weird error:
and it goes on and on.
Line 45 in the code is ” if(abs($x) > 30 && $stable > 30) {”
any ideas?
May 25th, 2006 at 10:20 am
Ian,
It sounds like it’s having trouble reading the output of AMSTracker. Can you post a comment containing the output of this command?:
AMSTracker -s -u0.01 | head -10May 25th, 2006 at 10:23 am
Can’t exec “AMSTracker”: No such file or directory at smaxpose.command line 32.
readline() on closed filehandle F at smaxpose.command line 33.
It’s in the same directory as smackbook and the amstracker program.
May 25th, 2006 at 10:35 am
I’m afraid I’m new to working with code and can’t quite get this to work.
What I did was to create a new file with xcode, paste in the script and then save it as smaxpose.command. I then ran the terminal command to make it executable, put the AMSTracker binary into the same directory (Users/my username/ and then ran smaxpose.command from the finder.
All that happens though is this:
Neils-PowerBook:~ Neil$ /Users/Neil/smaxpose.command; exit
Can’t exec “AMSTracker”: No such file or directory at /Users/Neil/smaxpose.command line 32.
readline() on closed filehandle F at /Users/Neil/smaxpose.command line 33.
logout
[Process completed]
Which bit am I doing wrong?
Thanks.
May 25th, 2006 at 10:36 am
Sam, for security reasons, Unix systems don’t put your current directory in your PATH. You can work around the problem by either moving AMSTracker to somewhere in your PATH (in the terminal, run the command “echo $PATH” to find a list of locations; /usr/local/bin is the best choice), or simply change line 32 in smaxpose.command from:
to
and save the file (you’re just putting ./ in front of AMSTracker).
But in order for that to work, AMSTracker will always need to stay in the same directory as smaxpose.command.
Hope this helps,
Brian
May 25th, 2006 at 10:39 am
If you do decide to put AMSTracker in your PATH, and you aren’t a habitual Terminal user, you might not have /usr/local/bin in your path to begin with! You can issue these commands to make sure the directory exists and is in your path:
then quit and restart the Terminal application and when you run the command “echo $PATH”, you should see /usr/local/bin in the list:
May 25th, 2006 at 10:50 am
Neil,
I just updated the entry with a slightly different version of smaxpose that should work for you. The other version required you to put AMSTracker in your Unix PATH, which is probably more hassle than necessary.
May 25th, 2006 at 10:55 am
Brian,
Thanks very much. The script now executes but I get this repeating again and again:
Neils-PowerBook:~ Neil$ /Users/Neil/smaxpose.command; exit
“Simulating” AMS hardware in software
Use of uninitialized value in numeric gt (>) at /Users/Neil/smaxpose.command line 45, line 2.
With the last figure increasing.
May 25th, 2006 at 11:12 am
[...] I came across this page, The Apple Motion Sensor As A Human Interface Device, where Apple’s Sudden Motion Sensor’s information can get translated to keyboard or mouse information using this program: AMS2HD. Browsing web pages, playing games, even orienting windows can be controlled by tilting your PowerBook or iBook. Some pretty sweet shtuff. You may have seen the SmackBook desktop switching video, or even the Exposé flavored approach. Here’s a video of someone playing Neverball. [...]
May 25th, 2006 at 11:27 am
Thanks for the post- your links/info led me to other great sites as well. Will be installing as soon as I can!
May 25th, 2006 at 12:14 pm
Neil,
Sorry to hear that it’s not working. What model of Mac do you have? I’m concerned that it says that it’s “Simulating” the AMS hardware. This suggests that you have a model of Mac that’s not supported by Amit’s program.
Can you post the output of this command?:
./AMSTracker -s -u0.01 | head -10That will let me know what kind of results the smaxpose script is getting from Amit’s AMSTracker.
May 25th, 2006 at 12:18 pm
Brian,
I have the last of the range of Powerbooks. I’ve been using Amit’s AMS2HID for a while now so I would have thought that AMSTracker would work.
Thanks
May 25th, 2006 at 12:19 pm
Brian,
I have the last of the range of Powerbooks. I’ve been using Amit’s AMS2HID for a while now so I would have thought that AMSTracker would work.
The output from that command is:
“Simulating” AMS hardware in software
127 127 0
127 127 0
127 127 0
127 127 0
127 127 0
127 127 0
127 127 0
127 127 0
127 127 0
Thanks
May 25th, 2006 at 12:30 pm
Thanks, Neil. The error was coming from the fact that the “127″ in the output of AMSTracker was never triggering the line of code that read “stable++”. This meant that the variable named “$stable” was never being assigned a valid value.
I have fixed the bug in the smaxpose2.command file, but unfortunately, it looks like there is a problem with the current AMSTracker and your model PowerBook. You can test for sure by running
./AMSTracker -s -u0.01and moving your PowerBook around.If you do see something other than
127 127 0, please post it, and I’ll see if I can make smaxpose.command work with it.May 25th, 2006 at 12:48 pm
Okay, I got the message “AMS hardware present and initialized” the first time but no actual response to moving or tapping. After I tried stopping and re-running the script, I just see “Simulating” AMS hardware in software”
Restarting leads back to the beginning of this again.
May 25th, 2006 at 12:58 pm
I really don’t know what’s going on…
Running ./AMSTracker -s -u0.01 mostly gives values of 127 127 0, but as I rotate the computer I get values like:
-10 21 0
-11 19 0
-18 13 0
-13 127 0
Thanks for taking a look at this problem, I’d find using exposé like this very useful so if there is something you can do I would appreciate it.
Thanks again.
May 25th, 2006 at 3:05 pm
Neil,
Did you try the most recent version of smaxpose (the one that should fix the Use of uninitialized value error)? That might work, but since you need to rotate the computer to get AMSTracker to do anything, you may need to rotate it to get smaxpose to work (if smacking doesn’t work).
If rotating does work, then it’s possible I could get some meaningful values out of AMSTracker on your model of machine. When you smack it (gently, of course
does AMSTracker still say “127 127 0″ or does it change?
May 25th, 2006 at 3:18 pm
It seems to be working! But only intermittently though. On tapping, AMSTracker outputs:
1 -3 54
1 -2 54
0 -2 55
1 -2 54
1 -3 54
7 -16 55
-3 5 57
-5 5 54
2 -3 57
But this doesn’t trigger exposé consistently.
May 25th, 2006 at 3:51 pm
Thanks, Neil. I just gave this a try with my stepson’s iBook, and I was getting different numbers, and also experienced the ‘“Simulating” AMS hardware in software’ error message. You might want to try playing with the numbers of line 45:
if(abs($x) > 30 && $stable > 30) {I was able to have some success with
if($stable > 5) {but that’s when I started getting the ‘“Simulating” AMS hardware in software’ error and it stopped working at all. I’ll look at this some more in the next few days, but you should also check out the comments in Erling Ellingsen’s original piece, since I’ve seen a few people having similar problems with PowerPC Macs.
May 25th, 2006 at 5:04 pm
Excellent! It’s working pretty consistently with a tilt, I’ll play with it some more and see if I can get it to work with a tap.
Thanks for this excellent app and your help!
May 26th, 2006 at 7:30 am
[...] Apple, as many other manufacturers, introduced some times ago a technology that aim to avoid hard disk damage when your laptop fall off. The technology called SMS (Sudden Motion Sensor) is able to detect the direction and the speed of the movement. This is not a news, the first introduction of this technology from apple it’s more than a year old and I think that Sony introduced it even earlier, anyway that’s not the point. What’s fascinating here it’s a bunch of unplanned use and hacks that are popping out all over the net: [here] you can see how tho switch from a virtual desktop to another simply hitting the side of your screen. [here] you can see how to activate Exposeé by hitting the table. [here] (and this is my favourite) you can lern how to transform you apple laptop into a Jedi Weapon. [...]
May 26th, 2006 at 12:28 pm
I’ve try smaxbook.command and smaxbook2.command on my iBook G4 1.33ghz and it’s not working : with the first one, there is an infinite loop and with the second Simluating is displayed in Terminal and nothing happened.
But AMSVisualiser and AMStoHID works well.
My english is probably not verry good, Sorry
David (French)
May 26th, 2006 at 12:51 pm
David,
Please check out some of Neil’s comments and my responses. It looks like G4 Macs don’t work well with AMSTracker, although you may have some luck modifying line 45 (see my earlier comment) of the script. Please be sure to also look at the comments in Erling Ellingsen’s original piece, since I’ve seen a few people having similar problems with PowerPC Macs.
May 26th, 2006 at 2:54 pm
Hello.. i have a little problem, i have an iBook G4.. the one before the macbook…
I succersfully install everything.. i have the DesktopManager working when i hit the side of my screen!!.. its very very cool.. but i dont see the point (in my case) of using virtual desktops.. But i like the expose one.. everything works the expose opens but the problem is, thet it keeps opening and closing like crazy and it wont stop until i close Termina here is the script i use :
use strict;
my $SENSIBILITY = 13;
my $TIME = 80; # (0.05 seconds)
open F,”./AMSTracker -s -u0.005 |”;
my $stable;
my $foo = ”;
while() {
my @a = /(-?\d+)/g;
print, next if @a != 3;
if((abs($a[1]) + abs($a[0])) 5) {
$stable = 0;
`osascript -e ‘tell application \”System Events\” to key code 101′`
}
}
The smaxpose2.command doesnt work for me.. so i combine them.. hahahaha.. i really dont know what i did… what should i do, to just trigger expose once and not endlessly?.. ??
By the way… sorry if i make no sense.. english is not my first language!!
May 26th, 2006 at 3:45 pm
Heferkimbo,
It sounds like it’s getting over-sensitive to the motion. Have a look at Erling Ellingsen’s original piece,. There are some updates at the top that address users of G4-based Macs. You should be able to apply those suggestions to smaxpose2.command.
May 26th, 2006 at 5:21 pm
Hi all,
i made out a little script for my ibook G4 that uses the SMS to switch between all the opened windows when you it the computer on the right, and that launches Exposé when you hit it on the left.
Can be found here: http://morgan.1er.free.fr/divers/smackmeuh.zip
Hope that it could help.
May 26th, 2006 at 8:48 pm
Its not working…. and everutime i run the scripts and close them, i have to restart the machine.. if i dont, i get the “Simulating” AMS hardware in software….
I will wait for more people to post their experiences.. and see if i can use them…
By the way, in order to keep the smaxpose runing, the Terminal must be open all the time right?? ..and everytime i turn the mac on i have to launch everything again.. isnt there a way to launch them on start?
May 27th, 2006 at 11:07 am
I have put together a nice package for smackbook.
its got all you need for an intel macbook to run
http://eamonn.designandsolve.co.uk/Projects/462C4CE6-0DF2-4DAA-9C78-EC4C98083DB6.html
May 27th, 2006 at 1:33 pm
Heferkimbo,
You could open up System Preferences, click Accounts, and then select Login Items. If you drag smaxpose.command to the list of startup items, it should launch automatically when you log in. However, you will need to edit smaxpose.command at line 32 and replace “./AMSTracker” with the full path to AMSTracker. For example, on my computer, I have AMSTracker in /Users/bjepson/bin/AMSTracker, so my line 32 needs to look like this:
May 27th, 2006 at 11:18 pm
Hello i did it… but it just opens the file with Text Edit.. but thats because it is not .command, in my case i just can make it work with .pl, i downloaded Morgan’s script and now expose work perfectly!!!!.. but still, everytime i turn on the computer i have to go to terminal cd /applications/smackbook ==> perl smaxpose.pl and it works!!!
I think if i can make smaxpose.command work i will be able to run it from startup with login items!!.. but all i get when i make smaxpose.command executable with terminal is this:
Last login: Sat May 27 23:13:49 on ttyp1
/Applications/smackbook/smaxpose2.command; exit
Welcome to Darwin!
dsl-201-121-217-207:~ iBook$ /Applications/smackbook/smaxpose2.command; exit
/Applications/smackbook/smaxpose2.command: line 1: use: command not found
/Applications/smackbook/smaxpose2.command: line 2: my: command not found
2006-05-27 23:14:12.779 open[385] No such file: /Users/iBook/F,./AMSTracker -s -u0.01 |
/Applications/smackbook/smaxpose2.command: line 5: syntax error near unexpected token `)’
/Applications/smackbook/smaxpose2.command: line 5: `while() {’
logout
[Proceso completado]
May 28th, 2006 at 10:08 am
Heferkimbo,
In order for it to work as a login item, it needs to have .command at the end.
What’s the first line in the file? In order for it to work correctly, it should have the same line (#!/usr/bin/perl -w) at the top as my original script. This tells Mac OS X to treat it as a Perl script rather than the default for .command files, which is to treat it as a standard shell script.
Also, it looks like you have a type in the path to the AMSTracker file. The /Users/iBook/ needs to be in the double quotes, as in:
Looks like you have it in front of the “F”
May 28th, 2006 at 2:29 pm
Thank you very much for your help Brian.. it works!! its very cool… i love your expose script!!
June 4th, 2006 at 10:54 am
[...] Erling Ellison’s Smackbook Hack is described here (look in the comments for complied versions) (and as a sidenote, Ellison’s blog is only 2 entries long and already looks promising… I haven’t seen a good Mac Hack blog in a long time). Smack Exposé and Bump Tunes both riff off SmackBook and are self explanatory. [...]
June 5th, 2006 at 3:22 pm
Hello.. is there any way to do this:
————————————————————————-
335
For those without unix underpinnings, if you type
perl smack.pl &
insetad of
perl smack.pl
you don’t need to keep the terminal window open, as you’ve opened the script in the background.
————————————————————————-
but, for smaxpose.command?? i just dont like so much to have the terminal as asoon as i turn on my ibook..
December 11th, 2006 at 3:22 pm
…I just happened to find this site - though still have the problem.
I was running the script just fine and was curious how ’small’ I could set the time interval.
0.5, 0.25, 0.10, 0.05, 0.01 all worked and then finally 0.001 broke it.
Ever since I ran the -u0.001 I’ve been getting the
“Simulating” AMS hardware in software
I have the last gen of PowerBook G4 12″
September 3rd, 2007 at 5:01 pm
Can someone give me a step by step guide on how to do it?
I’ve got the AMSTracker and smaxpose.command both saved into a folder called Smackbook Expose.
what do i do?
bearing in mind, i’ve done absolutely no work with terminal before, so be gentle please!
December 12th, 2007 at 11:11 pm
hey i can’t seem to save the file after i put all the in for in the terminal file it just say cancel or terminate but i won’t sve what i put in and the only way i can get the smack pro to work is to leave that file open! and ideas
December 30th, 2007 at 11:14 pm
Thanx everyone for their posts. I got is to work with a new MacBook running OS X 10.5.1. I was wondering if anyone knew how to get it to work with spaces instead of expose?
December 30th, 2007 at 11:32 pm
Hi Curtis, if you’ve got Spaces set to start when you press F8, try changing 101 to 100 in the osascript line toward the end of the .command file
February 13th, 2008 at 6:10 am
hi…iv just got this smackbook thing yesterday..i got everythin sorted..but everytim i restart compt..i hav to start all ova again wit termainal…i read wat brian wrote bout smapose.command or somthing…but i cannot find where it is…a lil help plzz? wat do i need to do so that i dont hav to mess wit this terminal thing everytim i wanna use it thannks in advanceee
February 17th, 2008 at 6:26 pm
hello, im unexpirienced but i try to read and i have problem
ok i downloaded amstracker and the code
i made a (/usr/local/bin) and put everything inside
i made this code
/usr/bin/perl -w
use strict;
my $SENSIBILITY = 26;
my $TIME = 80; # (0.05 seconds)
open F,”./Users/getoutski/bin/AMSTracker -s -u0.005 |”;
my $stable;
my $foo = ”;
while() {
my @a = /(-?\d+)/g;
print, next if @a != 3;
if((abs($a[1]) + abs($a[0])) $SENSIBILITY && $stable > $TIME) {
$stable = 0;
$foo = $a[0] < 0 ? ‘key code 118 using {control down}’ : ‘key code 101′;
} else {
if($foo ne ”) {
`osascript -e ‘tell application \”System Events\” to ${foo}’`;
$foo = ”;
}
}
}
and saved it “smaxpose.command”
afterwards i run (chmod +x smaxpose.command) from terminal and make it executable
started both AMStracker and new executable
and i get only this
Last login: Mon Feb 18 00:20:48 on ttyp2
/Users/getoutski/bin/smaxpose.command; exit
Welcome to Darwin!
getoutskis-computer:~ getoutski$ /Users/getoutski/bin/smaxpose.command; exit
February 17th, 2008 at 6:40 pm
sorry again but also with this smaxpose2.command code it doesnt work, the same as above
help
February 17th, 2008 at 6:44 pm
uffff you gona hate me for posting so clumsy but…
when i try with smackmeuh.pl triggering it from terminal it works
but i really want it to work through executable so I can be happy as Heferkimbo
thanks in advance
February 28th, 2008 at 1:10 pm
Did anybody get this working with 2 differnet “claps” ?
Maybe: Left-smack = Expose, Right-smack = Spaces !
I have been trying this, and know that Expose is “100″ whereas Spaces listenes on ASCII 101 - But i have no idea how to get this into a perl script
Help ! Anybody ?
Thanks for that wonderful Blog !
April 29th, 2008 at 8:46 am
[...] I know: Sudden Motion Sensor hacks are passé. But I finally got around to playing with one that invokes Exposé, and now I’m hooked. I ended up modifying it to invoke Dashboard instead, which required [...]