How to capture a screen shot of all spaces
screencapture ~/Desktop/1.png
osascript -e 'tell app "System Events" to key code 124 using control down' # ctrl-right
sleep 0.5
screencapture ~/Desktop/2.png
osascript -e 'tell app "System Events" to key code 123 using control down' # ctrl-left
# montage ~/Desktop/1.png ~/Desktop/2.png -tile 2x1 -geometry +2+2 ~/Desktop/`date '+%y%m%d%H%M%S'`.png


montage comes with ImageMagick.