14

As some people might know, the default behavior for external links of Google Chrome is quite bad. I'm using Spaces, and opening a link in some application outside of Google Chrome while being on a different Space than the last used window of Chrome results in Chrome switching to the last focused window.

This behavior is just bad.

I want to change this behavior. On Windows, this is possible: How can you configure Chrome to open new browser instances in new windows rather than in a tab?

Sadly, I don't think this is possible on OS X Snow Leopard.

I'm already using a tool called RCDefaultApps. This is a system-control panel where I can specify default applications for different protocols. It just lacks the feature to specify additional command line arguments for the default application.

Can anyone help me there? Every hacks (aside from creating a custom Chromium build) are acceptable.

1
  • It's amazing to me that this is still a problem. I've complained to Google multiple times, as I imagine many others have as well. All they have to do is make it an option. Other browsers have this option. Why they refuse to fix this is beyond me. Commented Feb 12 at 18:38

6 Answers 6

9

You can try using the AppleScript found on this page.

I just tried it out and it perfectly works fine in Chrome 12.0.742.122.

It's extremely easy to set up:

  • download the Bundle archive
  • double click it to unpack it
  • double click on OpenUrlInNewChromeWindow
  • open Safari and set the new "Browser" as the default browser in the Preferences.

new default browser

2
  • This seems to introduce a (very short) delay before opening the window, but it's exactly what I was searching for. Thanks!
    – jsadfeew
    Commented Aug 2, 2011 at 16:19
  • This applescript works wonderfully.
    – Nelson
    Commented Sep 7, 2011 at 16:06
6

Starting at Dave’s answer, I found that with Chrome 45, running osascript is no longer needed, and that with OS X 10.10, the Apple Script is not selectable in the system preferences. Here is how I solved it.

Create an Apple Script using the Apple Script editor, and export it as an application.

on open location theURL
   do shell script "/usr/bin/open '/Applications/Google Chrome.app' --new --args --new-window " & theURL
end open location

Install RC default app.

RCDefaultApp is a Mac OS X 10.2 or higher preference pane that allows a user to set the default application used for various URL schemes, file extensions, file types, MIME types, and Uniform Type Identifiers

In the system preferences, open the new default-apps screen, go to the URL tab, and set the exported Apple script as handler for http and https.

4
  • Thank you so much. This is the only solution that worked for me, this has been driving me nuts for years. Commented Aug 3, 2016 at 16:42
  • I believe that RCDefaultApp no longer exists. Its successor apparently is Lord-Kamina/SwiftDefaultApps. Grab and install the preference pane, SwiftDefaultApps.prefpane, from the current release. Then assign your AppleScript app to be the default browser. This worked for me. Commented Sep 3, 2020 at 5:55
  • Thank you. Is it possible to disable the new window if, say, you're holding the Shift key? Commented Dec 14, 2020 at 19:38
  • 1
    Be aware that this breaks for any URL containing an & character! The user @Z0B has a fix for this below: apple.stackexchange.com/a/392887/37478 Commented Feb 16, 2023 at 22:17
2

I've been unable to make it work too.

What I was trying to do was to use the following command:

open Google\ Chrome.app/ --new --args new-window www.google.com

But that opens a new Chrome that instantly closes (if Chrome is already open). I was planning on wrapping the above command within a bash script and then let it have arguments (for the URL).

But since the above command failed to work, I'm still thinking about this. So far I believe it's not "possible" without some modification to Chromium, but I might be overlooking something. It's early and I haven't had coffee yet. ;)

1
  • Yup, I tried that too. (with "google.com" instead of "Google Chrome.app") Both version don't work.
    – jsadfeew
    Commented Mar 3, 2011 at 16:38
2

This works on Mavericks:

open /Applications/Google\ Chrome.app --new --args --new-window https\://www.google.ca

followed by:

osascript -e 'activate application "Google Chrome"'

Tested in sh, bash and zsh.

For some reason, if I try to put them on the same line like so:

/usr/bin/open /Applications/Google\ Chrome.app --new --args --new-window www.google.ca; /usr/bin/osascript -e 'activate application "Google Chrome"'

...the second part doesn't complete. I assume that's because it's too close on the heels of the first command. So try this:

/usr/bin/open /Applications/Google\ Chrome.app --new --args --new-window www.google.ca; sleep 1; /usr/bin/osascript -e 'activate application "Google Chrome"'

Note that you don't need to specify the http:// part of the url at the end for it to work, but if you do, you need to escape the colon (:).

To make this script my default browser, I created an applescript and exported it as an application and then opened Safari Preferences and set the application as my default browser. Here's the Applescript code:

on open location theURL
  do shell script "/Users/[myusername]/bin/openUrlInNewChromeWindow.sh " & theURL
end open location

Replace [myusername] with your actual username.

2
  • The reason I prefer this solution to the one by mwidmann is that this one will close after opening the URL, whereas the the other one seemed to need to stay open in order to work. This meant that OpenUrlInNewChromeWindow was always in the CMD-Tab list of running apps, and every time I opened a URL, I had to tab twice to get back to the previous app.
    – Dave
    Commented Nov 4, 2014 at 4:36
  • I can confirm that use of RCDefaultApp per Michael Schmid also works on OSX El Capitan (10.11.1).
    – Dave
    Commented Nov 21, 2015 at 6:40
2

Security addition to the other answers [1]

One should quote the URL for security reasons and as it might contain special characters which need escaping when used as a string in bash (e.g. '&' and '$').

Otherwise the opened URL might be wrong and a maliciously crafted URL could even run an arbitrary command on your machine. Tested on macOS Catalina (10.15) and lower.

To put it all together, the updated script should look like this:

on open location theURL
    do shell script ("open -a 'Google Chrome' --new --args --new-window " & "'" & theURL & "'")
end open location

Or if you prefer your commands with full path (as in Michael's case):

on open location theURL
   do shell script "/usr/bin/open '/Applications/Google Chrome.app' --new --args --new-window " & "'" & theURL & "'"
end open location

The important part in both scripts are the quotes around the URL at end of the middle line.

[1]: Would have commented on the others' answer but don't have the required reputation, so I made a new answer.

1
  • 1
    Not only does this fix a security hole— it also fixes a total breakage on any URL containing a & character! This fix should be included in Michael Schmid's answer. Commented Feb 16, 2023 at 22:19
-1

The --new-window command option did it for me. ("C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --new-window https://www.google.com)

1
  • 2
    This is for Windows — please edit to refer to OS X.
    – grg
    Commented Jan 13, 2014 at 19:13

You must log in to answer this question.

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