2

On Mac OS 10.6.6, I want to make a bash alias or function that will run Google Chrome. Launching Chrome is easy: "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome". The problem is how to detach the Chrome process tree from Terminal.app so that when I close the terminal window, it doesn't kill Chrome. I have tried all of the following, to no avail:

"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" &

nohup "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"

"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" &
disown

screen "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"

screen "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" &

Any suggestions for how to truly detach the Chrome process tree from Terminal.app? Alternatively, is there another way to make a command-line shortcut to launch and detach Chrome?


EDIT: Note that the answers to this question apply equally well for launching other applications besides just Chrome.

3
  • Please edit your question to apply to all applications. We don't need a copy of this topic for every Mac application under the sun.
    – Daniel Beck
    May 7, 2011 at 4:26
  • Not what I meant. Since we keep track of the history of each post, there's no reason to let old content survive. I'd suggest you edit the title to be more generic ("Launch Mac application detached from Terminal" or something like that) and only use Chrome as an example. But that's just my opinion.
    – Daniel Beck
    May 7, 2011 at 4:33
  • @Daniel Feel free to make whatever edits you want. I see you have enough rep and are quite knowledgeable May 9, 2011 at 2:13

2 Answers 2

1

Try this:

open "/Applications/Google Chrome.app"

6
  • Nice! Thanks. Weirdly, if you use the full path to the executable, it spawns a new terminal window: open "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" . Any idea why? May 7, 2011 at 4:17
  • @Jon open uses Launch Services to determine what application to open a file with. If you do it like William suggests, it opens the Mac application bundle, but you start the unix binary itself, which gets a window for console output (stdout). open returns immediately, so there's not a lot of other options. You can also use open -a "Google Chrome" to let Launch Services determine which registered copy of Google Chrome to start.
    – Daniel Beck
    May 7, 2011 at 4:21
  • @Daniel Beck Apparently this also works: open -a "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" May 7, 2011 at 4:29
  • @Jon Sure, but what's the point? Since it's an application, it'll get started with or without the argument -a. The semantics are slightly different (open the file ... using the default application for that type, and open the application ...), but the result is the same.
    – Daniel Beck
    May 7, 2011 at 4:29
  • @Daniel Try it. Without the -a launches a new terminal window, which is annoying. With the -a does not, so I would prefer the latter. May 7, 2011 at 4:31
1
open -a "Google Chrome"

This will open Chrome without regard to where it is installed, which may be desirable over a hardcoded path.

Also note that using open differs from running the executable directly in that it will not launch a second copy of Chrome. This is correct Mac behavior; running the executable directly should not be done unless you have a special need such as passing command-line arguments (which a proper Mac application should never need in normal circumstances).

2
  • 2
    open -na "Google Chrome" does open a second instance. open -a "Google Chrome" --args "someArg" passes arguments.
    – Daniel Beck
    May 7, 2011 at 18:00
  • Interesting. --args is apparently new in 10.6, but -n is new to me as well. Evidently I haven't read the man page for open in a while.
    – Kevin Reid
    May 7, 2011 at 20:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .