Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Set default browser #154

Open
sindresorhus opened this Issue · 10 comments

5 participants

@sindresorhus

Is it possible to programmatically set the default browser?

Either through a Plist or AppleScript or something.

Would be useful to have in .osx

@sapegin

Chrome has command line argument for this: --make-default-browser (example). I’m not sure it’s possible for other browsers.

@sindresorhus

Neat, but that doesn't solve it for wanting Chrome Canary, Firefox or any other browser as default.

@mathiasbynens

@sapegin: Thanks for the info! I didn’t know about that Chrome flag.


I did some digging, and it seems defaults read com.apple.LaunchServices LSHandlers returns an array containing entries such as the following (assuming Google Chrome Canary is the default browser):

        {
        LSHandlerContentType = "public.html";
        LSHandlerRoleAll = "com.google.chrome.canary";
    },
        {
        LSHandlerContentType = "public.xhtml";
        LSHandlerRoleAll = "com.google.chrome.canary";
    },
        {
        LSHandlerRoleAll = "com.google.chrome.canary";
        LSHandlerURLScheme = http;
    },
        {
        LSHandlerRoleAll = "com.google.chrome.canary";
        LSHandlerURLScheme = https;
    }

As there are lots of other entries though, it’s kinda tricky to add/modify these values cleanly using the defaults command. However, this could easily be done using duti (ref. #54) using a settings file like this:

com.google.chrome.canary public.html all
com.google.chrome.canary public.xhtml all
com.google.chrome.canary http
com.google.chrome.canary https

(Untested, but it should work.)

To set another browser as the default, simply look up its bundle ID and use it instead of com.google.chrome.canary.

@kevinSuttle

@sindresorhus You can't make Chrome Canary your default browser. Just a heads up.

@sindresorhus

@kevinSuttle :( I don't understand the restriction...

@kevinSuttle

@sindresorhus It's apparently so it can be ran side by side with the stable builds.

http://www.google.com/intl/en/chrome/browser/canary.html (Bottom right: Side by Side Install).

@sindresorhus

@kevinSuttle you can actually set Chrome Canary as default, just not programatically.

Go into Safari and set it there. Works great for me. But would be awesome to have this preconfigured in my dotfiles.

@kevinSuttle

@sindresorhus Hm. I did not know that. Thanks! :thumbsup:

@miketaylr

I just wrote the following to do this in Python: https://gist.github.com/miketaylr/5969656

@mathiasbynens

@miketaylr Awesome! Nice work.

@marshnmedia marshnmedia referenced this issue from a commit
Commit has since been removed from the repository and is no longer available.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.