Script making Chrome the default browser on macOS

You would think it would be fairly simple to script changing the default browser to Chrome in macOS. It’s not, as far as I can tell! I’d love to be corrected on this.

Script that changes Launch Services

I wrote up a script that changes the default browser silently, but it works well only the first time you run it.

If you run it again to switch to another browser, you may have to reboot for the change to take effect. Sometimes changing the default browser through the GUI and then running the script again will have it work again.

That means it’s a bit messy. On the other hand, in terms of practical use, you’re not likely to want to script changing the default browser multiple times on one machine—the whole point of scripting it is likely to just make an initial default the user can change later on her own should she choose to, and she can use the GUI to do that.

If you want to use this in conjunction with Outset but not have the settings change for existing users (only new ones), you can use this preinstall script to fake-run the login-once script for each existing user.

I think this is a great option (and not just because I worked hard on it), but I also outline below some other options.

cdef and defaultbrowser

cdef and defaultbrowser allow you to set the default browser. Unfortunately, as far as I can tell, all that does is pop up the regular GUI “set default browser” dialogue: Again, if someone knows of a silent option I don’t know about, please leave a comment below, and I’ll update this entry.

duti works great… but not for Chrome

In Using duti to script default applications for Macs, I detail the steps for using duti in general, which works great… in general. It just chokes on setting the default browser. If you try to use duti to set Chrome as the default browser: public.html all public.xhtml all http all https all
you will get the error:
failed to set as handler for public.html (error -54)

7 responses to “Script making Chrome the default browser on macOS”

  1. Have you since you wrote this article perhaps made a mobileconfig that you would share ? Or do you have a script that do the same in login-every ?

    • There is no .mobileconfig profile that changes the default browser.

      And, no, there isn’t one that can change it every login. I thought I was clear about that from this sentence:
      I wrote up a script that changes the default browser silently, but it works well only the first time you run it.

      So, yeah, the first time you run it, it works, and then the next time, maybe not.

  2. I’ve tried implementing this script on initial provisioning, and it seems to work..but it messes with the app icons. Have you seen that at all? I’m executing via a Jamf policy, so that might be part of it.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.