Switching Spaces from the command line

Apple have no way of directly controlling Spaces from Applescript or from the command line so a little bit of slight of hand is needed.

osascript -e 'tell application "System Events" to keystroke "2" using control down'

This will Send a CTRL and 2 which will directly change to Space 2.  If you use a different Qualifier key change the “using control down”  to the key you want.  Command, Control and Alt

However doing this too much or too quickly can cause the Dock to crash and stop allowing keyboard input.  Yes I know it strange that the Dock controls Spaces but thats Apple for you.  Just kill the Dock and all will be fine.

sudo killall Dock