SmackBook with Leopard Spaces
SmackBook was originally a name given to the method used to switch between virtual desktops in Richard Wareham’s Desktop Manager using the MacBook’s built-in motion sensor. You would “smack” the MacBook on the side, and the sensor would read the movement and trigger the program to go to the desktop corresponding to the direction of the smack. Leopard’s spaces has made Desktop Manager nearly obsolete, but thanks to Jason Shen we can once again use it for SmackBook thanks to a script he’s written.
First you will need to download a few files:
- smackleopard.command, the file that contains the sensitivity information and calls for the system event to switch spaces, and
- AMSTracker, the command-line program that retrieves acceleration data from the Sudden Motion Sensor
Once you have downloaded the 2 files, you will need to place them in the same directory. After that, you might want to open the smackleopard.command file with TextEdit to modify the sensitivity.
To change the sensitivity find the following lines and modify both the numbers indicated. The higher the number, the harder you need to smack.
if(abs($x) > 30 && $stable > 30) {
$stable = 0;
If you aren’t using the default keyboard shortcuts to switch between spaces (Control + Arrow keys), you will need to modify the file to reflect the shortcuts. I for one use the Option + Arrow keys to toggle spaces so I changed the following code
`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'`
into this
`osascript -e 'tell application \"System Events\" to keystroke (ASCII character 28) using option down'`
} else {
`osascript -e 'tell application \"System Events\" to keystroke (ASCII character 29) using option down'`
I also swapped the keystroke parameters (ASCII character 28/29) to reverse the direction that spaces switch in to my liking.
Once you have configured the smackleopard.command file, you will need to change the script’s permission so that it becomes executable. Open up Terminal (/Applications/Utilities/Terminal) and switch to the smackleopard.command directory using the cd command. If it is on your desktop, you would type in the following:
cd /Users/myusername/Desktop
Change permissions with the following command:
chmod +x smackleopard.command
Now assuming that both smackleopard.command and AMSTracker are in that same directory, you may now run it by typing in the following:
./smackleopard.command
To end the SmackBook system events, just press Control + C while it is running in Terminal. Watch it in action in this video, though the instructions may be a bit confusing to the inexperienced.
Tags: ams, Leopard, motion sensor, smackbook, sms, spaces |

March 16th, 2008 at 12:39 pm
I am having trouble getting it to work.
In Terminal, it says “AMS is initiallized or whatever the technical term is.
Now what?
March 16th, 2008 at 12:43 pm
Now you should be able to smack the MacBook to change spaces. Make sure the keyboard shortcut keys are enabled in the Spaces preferences pane.
March 16th, 2008 at 12:48 pm
I looked in that pane.
No luck with finding the “enable shortcut keys” in Spaces pane.
How do i get there?
March 16th, 2008 at 12:53 pm
Once you are in the Spaces pane, there should be a “Keyboard and Mouse Shortcuts” section at the bottom. Beside the “To Switch between spaces:” make sure its set to “^ Arrow Keys”.
Hope that helped =)
March 16th, 2008 at 1:14 pm
It is set the way you are referring, and still no luck.
When i try to use SmackBook, i end up looking like n idiot who just hits his screen.
I have the newest version of Macbook. Does that make a difference This tutuorial was publishd this morning.
March 16th, 2008 at 1:32 pm
Hmm, try lowering the sensitivity and running the script again maybe. This trick should work even on the new Macbooks.. Also don’t close Terminal once you run it… try using the Hide function on it instead.
March 20th, 2008 at 5:18 pm
I got it work, but i got some problems. Switiching Spaces this way is a little bit glitchy.. It is not a flowing procedure, but thx anyway.
Im using a mbp
March 22nd, 2008 at 10:07 am
sh: -c: line 0: unexpected EOF while looking for matching `”
sh: -c: line 1: syntax error: unexpected end of file
this is the message that shows up in terminal when i smack my MacBook white 2 ghz.
April 11th, 2008 at 3:33 pm
This is great, but AMSTracker stops running when I close terminal and therefore smackbook only works with terminal open. How do I keep AMS tracker running in the background?
April 13th, 2008 at 3:33 am
I made some changes that make the script a little more predictable and easier to fine tune. It doesn’t change spaces by tilting so you can move around while the script is running and no worries. The credit all goes to the author though. I don’t even know perl.
April 13th, 2008 at 3:34 am
http://web.ics.purdue.edu/~aehumphr/smackleopard.command
April 17th, 2008 at 4:31 pm
I use command control alt + arrow to switch spaces on my macbook pro,
how do I tweak the script to hold down multiple keys?
Yours
Andreas
April 18th, 2008 at 4:56 am
It works, when i switch between spaces with Control + Arrow, it works fine, but with the smackbook script its very slow and laggy. On a brand new 2.4 ghz MBP. Why?
April 24th, 2008 at 11:42 pm
What permissions are needed to run a .command file
It’s not letting me run the file, even though I have read and write permisssions.
May 6th, 2008 at 9:40 am
Permission for execution are required. Therefore you have to type
chmod +x
You may see the permissions by typing
ls -l
in the working directory.
May 9th, 2008 at 7:12 am
hey dude u no when u can type su before chmod and it gives u the password. after i cant tpe anything no password at all.
can u please help thanks.
May 9th, 2008 at 3:56 pm
i just posted a comment on how i type su and crap, but can u tell me wat u do when u get to the password thing because i cant type anything, it wont let me type anything
please help cause i want this to work.
thanks
May 9th, 2008 at 10:21 pm
@Gio
You can type, but it just doesn’t show it. Type the password and press enter and it should get you in.
May 11th, 2008 at 9:50 pm
ok i did this no problem and ams hardware present and initialized and when i go to smack it nothing! i have all the short cuts set to the correct spots and i have a powerbook g4. i know this has the sms (sudden motion sensor) in it. in that long pause my computer just went crazy!! i smacked it in the process earlier about 20 times total it started switching between spaces for like 3 minutes when i didn’t even touch my computer! im not sure what is up but it works just not controllably!
May 12th, 2008 at 11:56 am
i did what you said but it doesnt work.
Is it your login password that you type or is it something else because i type my login and it says su: sorry
please can you help again thanks.
May 12th, 2008 at 8:45 pm
nvm i got it to work. i read a comment on another website and it said to delete the pl. that safari adds to the smackleopard.command file. Thanks anyways for the help.
May 21st, 2008 at 7:07 am
Hi there, i was just wondering if there was a way to get access to the command without having to run terminal?
May 21st, 2008 at 4:27 pm
i dont think you can from all the things I’ve read but otherwise all i know is that you have to have the terminal open to run smackbook.
May 22nd, 2008 at 5:39 pm
I’ve followed the instructions perfectly but it still doesn’t work
i think that it might be a problem with the chmod part something
like mabye i don’t have the right permissions to mess with stuff but i’m already an admin
May 22nd, 2008 at 7:29 pm
when I do everything terminal says
Last login: Thu May 22 17:25:31 on ttys001
Macintosh:~ corey$ cd /Users/corey/Desktop/smackbook
Macintosh:smackbook corey$ chmod +x smackleopard.command
Macintosh:smackbook corey$ ./smackleopard.command
./smackleopard.command: command substitution: line 1: unexpected EOF while looking for matching `”
./smackleopard.command: command substitution: line 2: syntax error: unexpected end of file
./smackleopard.command: command substitution: line 1: syntax error near unexpected token `(’
./smackleopard.command: command substitution: line 1: `osascript -e ?tell application \?System Events\? to keystroke (ASCII character 29) using option down?’
}: command not foundnd: line 1:
./smackleopard.command: line 34: use: command not found
./smackleopard.command: line 35: my: command not found
The file /Users/corey/Desktop/smackbook/F,./AMSTracker -s -u0.01 | does not exist.
./smackleopard.command: line 42: syntax error near unexpected token `)’
./smackleopard.command: line 42: `while() {’
Macintosh:smackbook corey$
May 22nd, 2008 at 10:53 pm
@ Corey:
Did you delete the .pl off of the smackleopard.command file that you downloaded?
And also when you download AMS tracker you have to take the one file out of the folder and copy it and paste it in the same folder or directory as the smackleopard.command. If you did that it should work, just get back to me and ill see wats wrong.
peace
June 11th, 2008 at 5:04 am
i have problem with my motion sensor. it work before , i use the liquid mac and mac saber applicatons and work with that, but now when i tried to make smack book i make a mistake and is not working. how can i reset it or fix it , i tried reboot i tried the enable comand but nothing. please if you know how write to my mail or here. thanks.
July 16th, 2008 at 6:46 pm
This is cool, I got this working and also the older version that required Desktop Manager. I can’t get it to go in a certain direction.
If I tap the right side I go to the left desktop but sometimes it also goes to the right.
Any Ideas on what I should tweak.
July 18th, 2008 at 5:37 pm
Got a question: is there any way to modify your or maybe better nellacon’s script to responding to the lighting sensors? somehow i feel a bit odd about smacking my laptop and more sensitivity just isn’t userfreindly enough (can’t work comfortably on my lap anymore)
thanks and great work!!!
July 22nd, 2008 at 10:06 pm
i really really want this to work.
also Im really new to macs, and modding and tweaks and all that stuff
but step by step would be greatly appreciated (even on saving to a directory thing> does that mean the same folder or something????????? sorry im such a nub.
nickmatteis@aim.com <<<<please email/post step by steps
July 31st, 2008 at 1:46 pm
i got the command file executable (finally!) and i tested the amstracker and it worked, so i put them both in a folder called “smackbookleopard.command” and put that on my desktop… i double click the script and get this :
Last login: Thu Jul 31 14:42:05 on ttys000
Nick:~ nicholasmatteis$ /Users/nicholasmatteis/Desktop/smackbookleopard.command/smackleopard.command ; exit;
Can’t exec “./AMSTracker”: No such file or directory at /Users/nicholasmatteis/Desktop/smackbookleopard.command/smackleopard.command line 41.
readline() on closed filehandle F at /Users/nicholasmatteis/Desktop/smackbookleopard.command/smackleopard.command line 42.
logout
[Process completed]
why doesnt this work?! tips / hints would be greatly appricated! c:
August 2nd, 2008 at 5:36 pm
@Nick
I know whats wrong, your command file is a shell file.
so its fine jut do the terminal stuff and it will work fine.
In order to edit the command file it needs to have a .pl at the end cause that was my problem running it. If that doesnt work download it with safari on your mac then when your done editing it just delete the .pl off the end.
If you have trouble check out my video on youtube.
http://www.youtube.com/watch?v=J9GV2A3qZb0
hope it works.
get back to me if you can.
August 3rd, 2008 at 8:37 am
This is cool, I got this working and also the older version that required Desktop Manager. I can’t get it to go in a certain direction.
If I tap the right side I go to the left desktop but sometimes it also goes to the right.
Any Ideas on what I should tweak.
August 12th, 2008 at 4:39 am
Any way to run this without having to leave Terminal open all the time?
August 22nd, 2008 at 10:52 am
use virtue desktops it works with out the terminal open.
September 5th, 2008 at 4:24 pm
my first install went fine but now every time i smack it terminal says “^[[5C^[[5D”
any ideas?
October 15th, 2008 at 12:55 am
/smackleopard.command
Can’t exec “./AMSTracker”: No such file or directory at /smackleopard.command line 41.
readline() on closed filehandle F at /smackleopard.command line 42.
October 16th, 2008 at 7:17 am
[...] Fonte. Postado na categoria OSX | [...]
November 11th, 2008 at 11:11 am
[...] Fonte. [...]