Switching the default browser

I’m using Google Chrome for work and Safari for my personal stuff (on a Mac).

That works well, but whenever I click links, the workflow breaks down, and links never open in the correct browser.

I end up copy-pasting one-time verification links from one to the other to use the correct login.

If only there were a quick way to switch the default browser!

I did some googling and found an old Applescript that didn’t work on the latest MacOS 15.2, so I used Claude to fix it.

When you build it and run it, it shows you a list of available browsers and the current default:

If you want to change to chrome, it’s easy as running defaultbrowser chrome. The problem is that you get this annoying pop-up.

Even more annoyingly, chrome’s pop-up is different when switching back to Safari.

It’s also burning my mental cycles to decipher if pressing Keep or Use will actually do the switch.

We can do better with Raycast.

I wrote about Raycast before; it’s an excellent piece of software that replaces the default launcher. The power is in its ability to be extended.

So let’s write a little wrapper around the defaultbrowser command that integrates with Raycast and can automatically close that annoying security pop-up.

This time with AppleScript. I added an easy way to find what the current default browser is by calling defaultbrowser —which. This just says “chrome” or “safari”. Then we can do the switch, wait for the pop-up, find out what to click on, and close it to confirm.

Finally, we tie everything to a keyboard shortcut in Raycast. I’m using Hyperkey to remap my Caps Lock to Cmd+Option+Shift+Command. I use + T as the second part of the shortcut.

Now all we need to do is press Caps Lock + T and we get this fine notification.

Press again to toggle. It takes two buttons and a few hundred miliseconds.

Perfection.

If you are a bit of a masochist: https://github.com/TajPelc/defaultbrowser

Or you can do what any sane person would do and get software that does this and more: https://sindresorhus.com/velja

Yours,

Taj

All writing