Set Chrome as Default Browser from Command Line

By  on  

Whenever I see a desktop GUI to accomplish a given web-related task, I'm dying to know the underlying operating system interaction to accomplish the same feat.  Many of the GUIs I use are just a front for a command line utility for that more experienced developers would use.

I set out to find the command line script for setting the system's default browser on OS X but apparently there isn't one, but I did find a command line script for setting Chrome as the default browser:

open -a "Google Chrome" --args --make-default-browser

The script above opens Google Chrome and asks for confirmation that you'd like to make it the default browser.  I'm not aware of what command line scripts would make other browsers the default browser, and I'm a bit annoyed that there isn't a single script to do so!

Recent Features

  • By
    Chris Coyier’s Favorite CodePen Demos

    David asked me if I'd be up for a guest post picking out some of my favorite Pens from CodePen. A daunting task! There are so many! I managed to pick a few though that have blown me away over the past few months. If you...

  • By
    JavaScript Promise API

    While synchronous code is easier to follow and debug, async is generally better for performance and flexibility. Why "hold up the show" when you can trigger numerous requests at once and then handle them when each is ready?  Promises are becoming a big part of the JavaScript world...

Incredible Demos

  • By
    Implement the Google AJAX Search API

    Let's be honest...WordPress' search functionality isn't great. Let's be more honest...no search functionality is better than Google's. Luckily for us, Google provides an awesome method by which we can use their search for our own site: the Google AJAX Search API.

  • By
    Using MooTools For Opacity

    Although it's possible to achieve opacity using CSS, the hacks involved aren't pretty. If you're using the MooTools JavaScript library, opacity is as easy as using an element's "set" method. The following MooTools snippet takes every image with the "opacity" class and sets...

Discussion

  1. Too bad that still prompts you to accept the make default browser action/choice. That kind of detracts from the ability to fully automate system provisioning for instance. :(

  2. Danie

    Or simply go here:

    OS X Yosemite:
    1 – From the Apple menu, choose System Preferences, then click General.
    2 – Click the “Default web browser” pop-up menu and choose a web browser, like Safari.

    OS X Mavericks or earlier:
    1 – Open Safari from the Applications folder, Dock, or Launchpad.
    2 – From the Safari menu, choose Preferences.
    3 – Click the General button.
    4 – Choose a web browser from the “Default web browser” pop-up menu, like Safari.

Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!