Is there a way in Mac OS X to stop applications from stealing focus, especially between spaces?

Solution 1:

This will prevent any autoswitching of Spaces, which meets your criteria, but does other things, too, that you may not want:

defaults write com.apple.dock workspaces-auto-swoosh -bool false
osascript -e 'tell application "Dock" to quit'

Solution 2:

There is also the '-g' option to 'open' that will run programs in the 'background' in that they won't steal focus away from the current app. Try

open -g /Applications/iCal.app

for instance. See here for details:

If you want to edit the Info.plist of some application to make this permanent, you can add the key

<key>LSBackgroundOnly</key>
<true/>

See here for details.

Solution 3:

(above user refused to let me cite the official documentation in my edits to his answer, so I'm adding it for the benefit of actual users who want to get the authoritative source of truth)

From man open

      -g  Do not bring the application to the foreground.

Example:

open -g -a /Applications/TextWrangler.app /path/to/myFile.txt