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,
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
).
- Open
System Settings
- Choose
Accessibility
- Choose
Keyboard
on the right hand side
- Choose
Keyboard Settings...
- Toggle
Keyboard navigation
toOn
Use keyboard navigation to move focus between controls. Press the Tab key to move forward, Shift-Tab to move backward, and Space to select.
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.