Download Widget

SmackBook with Leopard Spaces

March 16th, 2008
Filed Under: Tutorials

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:

  1. smackleopard.command, the file that contains the sensitivity information and calls for the system event to switch spaces, and
  2. 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: , , , , , |

39 Responses to “SmackBook with Leopard Spaces”

  1. Chris Says:

    I am having trouble getting it to work.
    In Terminal, it says “AMS is initiallized or whatever the technical term is.

    Now what?

  2. Eric Says:

    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.

  3. Chris Says:

    I looked in that pane.
    No luck with finding the “enable shortcut keys” in Spaces pane.

    How do i get there?

  4. Eric Says:

    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 =)

  5. Chris Says:

    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.

  6. Eric Says:

    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.

  7. Viper Says:

    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

  8. Rasmus Says:

    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.

  9. greymaien Says:

    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?

  10. Nellacon Says:

    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.

  11. Nellacon Says:

    http://web.ics.purdue.edu/~aehumphr/smackleopard.command

  12. Andreas Knudsen Says:

    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

  13. Erik Says:

    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?

  14. Aaron Says:

    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.

  15. Engywuck Says:

    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.

  16. Gio Says:

    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.

  17. Gio Says:

    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

  18. An Says:

    @Gio

    You can type, but it just doesn’t show it. Type the password and press enter and it should get you in.

  19. crazy mac man Says:

    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!

  20. Gio Says:

    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.

  21. Gio Says:

    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.

  22. Jack Says:

    Hi there, i was just wondering if there was a way to get access to the command without having to run terminal?

  23. Gio Says:

    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.

  24. Corey Says:

    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

  25. Corey Says:

    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$

  26. Gio Says:

    @ 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

  27. nikola Says:

    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.

  28. Mir Says:

    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.

  29. Karl Says:

    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!!!

  30. NiCKKKK Says:

    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

  31. N!ck Says:

    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:

  32. Gio Says:

    @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.

  33. Mir Says:

    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.

  34. JC Says:

    Any way to run this without having to leave Terminal open all the time?

  35. gio Says:

    use virtue desktops it works with out the terminal open.

  36. david Says:

    my first install went fine but now every time i smack it terminal says “^[[5C^[[5D”

    any ideas?

  37. jeff Says:

    /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.

  38. DOTMAC Says:

    [...] Fonte. Postado na categoria OSX | [...]

  39. SmackBook « marciogm Says:

    [...] Fonte. [...]

Leave a Reply