til

Today I Learned: collection of notes, tips and tricks and stuff I learn from day to day working with computers and technology as an open source contributor and product manager

View project on GitHub

Set Default Browser From the Command Line

This can be done using the tool: defaultbrowser

Works like a charm.

With no arguments lists your browsers and marks the one being the default.

$ defaultbrowser
  iterm2
* chrome
  firefoxdeveloperedition
  safari
  vlc
  evernote
  netnewswire

Setting it is simply by providing an argument, matching the list

$ defaultbrowser chrome

Do note that this displays a GUI dialog,

GUI dialog

If you want to go full command line, you have to tweak some settings on the newer versions of macOS. This is example is taken from: Ventura (13.4.1).

  1. Open System Settings
  2. Choose Accessibility
  3. Choose Keyboard on the right hand side

Accessibility Settings

  1. Choose Keyboard Settings...

Keyboard Settings

  1. Toggle Keyboard navigation to On

Use keyboard navigation to move focus between controls. Press the Tab key to move forward, Shift-Tab to move backward, and Space to select.

Window with keyboard Shortcuts

Now you should be able to tab through the dialog and press Space to select the browser you just requested as your default browser.

As bonus content I can offer you a CLI completion script for defaultbrowser for Bash

I myself have moved to Zsh and are using Fig. I have gotten a PR with a completion script (generator) for Fig accepted, so I am now using that.

References