Macro to toggle default browser between Safari, Chrome and Firefox

I constantly have to switch between 3 browsers: chrome (for google apps), safari (xpath scripting) and firefox (for proxy).

I tried in vain to create a macro which would allow me to toggle between the 3 apps.

The only solution I could conceive was sys pref → general → default browser drop down list, but my macro does not work

The ideal solution would be to prompt the user to
Press S for Safari
Press C for Chrome
Press F for Firefox

but I have no clue as to how to do so.

thanks in advance for your time and help

    tell application "System Events"
	tell process "System Preferences"
		-- insert GUI Scripting statements here:
		click pop up button 3 of window "General" of application process "System Preferences"
	end tell
end tell

I think you’d find it easier to install this command line tool and then build a macro that gets the user’s choice and runs it.

1 Like

thanks very much for your input.
1- pardon my ignorance and with all due respect: how would I know that a script taken off the Internet is safe ? My question applies to to Github and other scripts in general. It's always an issue that troubles me.
2- I would run it as a shell script ?
3- what is your preferred action to get user input of the type: s for safari (which would run defaultbrowser safari, f for firefox, c for chrome.

  1. An excellent question that’s hard to answer. Trust is a continuum, not a binary yes/no thing. I trust that command because its source code has been developed out in the open for several years, it's been linked to and recommended in many places, and I can see in the code which libraries are being called and (in a general sense) how they're being used. I'm not pretending I can do a real code review, but it's not that hard to read the source and see that the routines being called are not sending info out on the network.

  2. Yes, once you have input from the user, you run defaultbrowser in a one-line shell script.

  3. Well, frankly I was expecting you to already have some ideas on how to do this part. I was just trying to save you the hassle of programming a complex set of clicks and menu choices for setting the default browser.

1 Like

thank VERY much for your most clear and intelligent replies.
I totally understand the distinction between utopian certainty and high probability
As far as the input is concerned, no problem I will work it out.

Sorry, but I would disagree. If you are not an experienced Terminal/Unix command-line user, the instructions provided on the defaultbrowser Github page are woefully inadequate.

It is not stated there, but I believe that it requires Xcode to be installed to use the make command.

Unfortunately, every solution I have found requires Xcode to be installed.


I am working on a Macro to provide a solution to this, but it will probably be tomorrow before I'm ready to post it.

1 Like

thanks very much ! I look forward to seeing your solution. I was about to start installing X-Code
I was looking at these sites

Just a side question: do you have xcode installed ? Do you recommend it ?

Looks like Xcode will be required for any solutions that change the default browser. This is a good site to look at:
Installing Xcode on a Mac

Here's my solution:

MACRO: Change Default Browser

Let us know if this works for you.

Yes and Yes.

It does not hurt to have it installed, and occasionally, like now, you need to have it. It's free.

1 Like

thanks very much for a superb macro !

After xcode installation + license approval, everything works fine.

I have specific situation where I know which browser I want to switch to, and would like to avoid the user input part.

I would have 2 questions:

1- what would be the general procedure to add a browser (Vivaldi for example) to the list. If I trigger the macro and click on see all browsers, vivaldi looks like


PS Vivaldi has a nice note taking panel.

2- I sometimes know exactly which browser I need to set as default, and part of a macro.
For example, I created a macro (inspired from the forum) to batch open all Safari Reading List URL links in another browser, for example Firefox which, in my setup, has all the proper proxies configured.
I am trying to create a variant of your macro which would simply: set default browser to firefox (which I would include at the start of the reading list macro, and reset default to chrome at the end).

Is this correct ? how would I modify it as a stand-alone macro which sets the default to a specific browser be it chrome, firefox, safari or vivaldi ?

As far as I can see, the only action which actually sets the default browser (excluding the input) in your macro is the action/script below. The code is incomprehensible to me.

I would create variants for chrome, firefox, safari and vivaldi.

thanks again very much !

// Based on script by @Tom

import Foundation

let browserStr = ProcessInfo.processInfo.environment["KMVAR_Local__Browser"]!
LSSetDefaultHandlerForURLScheme("http" as CFString, browserStr as CFString)

Thanks again.

I installed XCode from the app store.

I notice on the Internet people asking how to uninstall the command line tool. Can you see any reason as to why someone would run into problems and want to uninstall it. ?

I am very sorry for sounding so cautious.

I explained this in the ReleaseNotes:

    (all shown in the magenta color)
  • CHANGE If Needed to Show List of Browsers on Your Mac
  • Must use format of BundleID__DisplayName

Look at the Action that sets the list for examples:

No need to create another version, just modify the existing macro to check for a %TriggerValue%, which you would pass as a parameter in a Execute Macro.
The simplest would be to just pass the Bundle ID of the Browser you want, like this:


OK, per your request, I have updated my macro to provide an option to call as a Sub-Macro with the Browser Bundle ID as the parameter. In which case the Prompt is skipped and there is no user interaction, unless the Bundle ID is invalid.

1 Like

thanks very much. Crystal clear !

So everything is tested and works fine, including use as a sub macro.
thanks for your detailed explanations
Since the macro takes a bit of time to execute, I was wondering if, when used as a sub macro, I should simply insert a pause or if you have a suggestion on how to use the pause until action.
thanks again

No, you should not need a Pause Until Action.
The macro is slow because it uses many swift scripts. I'm sure you can speed thinks up if you will remove all of the error checking and just run the last Swift script which does that actual change of default Browser. I don't recommend this, but that is a decision/risk you can make.

Here's the simplified Macro:

Below is just an example written in response to your request. You will need to use as an example and/or change to meet your workflow automation needs.

Please let us know if it meets your needs.


MACRO:   Change Default Browser WITHOUT Any Error Checking [Sub-Macro)

-~~~ VER: 1.0    2020-06-27 ~~~
Requires: KM 8.2.4+   macOS 10.11 (El Capitan)+
(Macro was written & tested using KM 9.0+ on macOS 10.14.5 (Mojave))

DOWNLOAD Macro File:

Change Default Browser WITHOUT Any Error Checking [Sub-Macro).kmmacros
Note: This Macro was uploaded in a DISABLED state. You must enable before it can be triggered.

1 Like

works perfectly. thanks very much !

1 Like