11

I have certain applications set to open in certain spaces, but would like them to open in the background and not switch the space just so I can watch them open.

Hennes
  • 64,768
  • 7
  • 111
  • 168
Philip
  • 1,213
  • 1
  • 21
  • 36

3 Answers3

10

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.

kenorb
  • 24,736
  • 27
  • 129
  • 199
Richard Lee
  • 101
  • 1
  • 2
  • This is nonetheless very interesting.... Maybe there is after all a more permanent way to make the open -g style change w/o other side-effects? – Philip Jul 31 '11 at 11:47
3

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'
wfaulk
  • 6,200
  • 5
  • 34
  • 45
  • Thanks; I'll give it a try. Do you know what other things? Do I just set the boolean back to true to undo it? – Philip Oct 17 '09 at 21:39
  • @wfaulk, yes, what are the "other things" this command does? – Josh Oct 28 '09 at 16:52
  • 1
    @Josh: largely that Cmd-Tab switching to an open application will not switch to a Space with an open window. Basically anything that would automatically switch you to a different space will be disabled. – wfaulk Oct 28 '09 at 20:09
  • Too bad there doesn't seem to be anything that can just solve the problem without the unwanted side effects. Bummer. – Philip Jan 12 '10 at 03:39
1

(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
Sridhar Sarnobat
  • 1,395
  • 2
  • 13
  • 25
  • This duplicates another answer and adds no new content. Please don't post an answer unless you actually have something new to contribute. – DavidPostill Jul 22 '16 at 21:35
  • No it is not the same as the above answer, mine gives the manpage reference which is helpful. I attempted to modify the above answer but my edits were rejected. I don't want to go reading through manpages to find out what `-g` officially means. – Sridhar Sarnobat Jul 22 '16 at 21:36
  • The other answer includes a link to the appropriate manpage. – DavidPostill Jul 22 '16 at 21:37
  • Please read this: http://meta.stackexchange.com/questions/8231/are-answers-that-just-contain-links-elsewhere-really-good-answers – Sridhar Sarnobat Jul 22 '16 at 21:38
  • "A link alone as an answer is a bad answer in my book. Links break and the answer becomes worthless later even if the linked material answered the question initially. At least if you include a summary, the answer can somewhat stand on its own." – Sridhar Sarnobat Jul 22 '16 at 21:39
  • I don't need to. "Are answers that just contain links" the other answer contain far more information than just links. It also says "I think that links are fantastic, but they should never be the only piece of information in your answer." which it clearly isn't. – DavidPostill Jul 22 '16 at 21:40
  • "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." is a more than adequate summary of what is needed from the first link. – DavidPostill Jul 22 '16 at 21:41
  • Bottom line, users in search of the answer to the question will not want to just blindly copy the `-g` flag without doing the proper research. I'm speaking from experience. – Sridhar Sarnobat Jul 22 '16 at 21:41
  • I don't want users paraphrasing when official verbiage could easily have been cited. – Sridhar Sarnobat Jul 22 '16 at 21:43
  • If this was refused as an edit (I see why), then you could have added this information as a comment to that answer... – Alex Oct 31 '22 at 04:40