How can I stop spaces from switching automatically?

Solution 1:

Stop Spaces from switching spaces due to an app coming to the foreground:

defaults write com.apple.Dock workspaces-auto-swoosh -bool NO && killall Dock

Or via the GUI: System Prefs > Spaces and then uncheck the checkbox at the bottom: "When switching to an application, switch to a space with open windows for the application"

Stop (slow down) Spaces from switching spaces if your mouse presses against the edge of the desktop:

defaults write com.apple.dock workspaces-edge-delay -float 60 && killall Dock