Select a Different Browser Under Certain Conditions

I use Safari as my daily browser and have always preferred to avoid Google products.

I'm now engaged in some work where I need to collaborate with others using the full suite of Gmail, Drive and so on and I have decided to (kind of) sandbox all my Google activity in the Chrome browser, which allows me to keep Safari (kind of) clean.

Question is, how can I use KM to use Chrome when I have a Google link (e.g. Google calendar, or Google drive link that arrives by mail) and Safari if not?

I thought about using a Key Modifier when clicking a link, though I couldn't work something out to get that to work (While Mail AND ctrl) and then I wondered if KM could change the Default browser for a moment before changing it back to Safari.

Any thoughts or clues welcome!

You could try this:


[Test] Open with Chrome.kmmacros (5.5 KB)


Make this available only in Mail.

You have to place your Mouse pointer over the link and press the trigger hotkey. It will open the context menu, select Copy Link, then test the link for Google crap and open it with Chrome if necessary.

If you know beforehand which link is clean and which is Google you can of course omit the link test and send it directly to Chrome.

1 Like

PS, for the other question:

and then I wondered if KM could change the Default browser for a moment before changing it back to Safari.

This works fine for quickly switching back and forth between Safari and Chrome:



You should see this dialog then:


If you don’t like the confirmation dialog you can automate the button press with KM actions (the non-default browser is always the right button):

[Edit:] @ccstone pointed out that for the Tab keystroke action to work you must have “All controls” enabled in System Preferences > Keyboard > Shortcuts:


[Test] Set Default Browser.kmmacros (2.6 KB)

1 Like

Hey Tom,

Bleep! I suspect you're right, and this is a “security” feature.

System Events can't press the button either.

But.

tell application "System Events"
  tell application process "CoreServicesUIAgent"
    tell window 1
      tell button "Use “Chrome”"
        action "AXPress" --> FAILS
        set value of attribute "AXFocused" to true --> WORKS
      end tell
    end tell
  end tell
end tell

From there you can use Keyboard Maestro to press the button.

-Chris


Generic-Test 01.kmmacros (3.0 KB)

1 Like

Hey Tom,

Sure.

tell application "System Events"
  tell application process "CoreServicesUIAgent"
    tell window 1
      tell (first button whose name starts with "use")
        set value of attribute "AXFocused" to true
      end tell
    end tell
  end tell
end tell

-Chris

Here’s the final macro (so far):



Default Browser Toggle.kmmacros (3.0 KB)

1 Like

Thanks to both Tom and ccstone, you’ve contributed some interesting ideas here - I really appreciate your efforts and time!

I will go through a couple of the doors you’ve opened for me and see what I can set up for myself.

Thanks again.

Hello Tom,

that macro doesn't work anymore it seems or im doing something wrong.
I get the following error:

/var/folders/6m/yxr0h3nn2fl242hkgjy_jgb00000gn/T/Keyboard-Maestro-Script-57DD174B-8BA0-42DC-85EA-9589BB5DDFCC:2:33: error: cannot convert value of type 'String' to expected argument type 'CFString'
LSSetDefaultHandlerForURLScheme("http", "com.google.Chrome")
^~~~~~
as CFString

I don't know what i can do to convert String to CFString. Is there anything im missing installation wise?

Cheers,

Frozen

Here is an up-to-date version.

1 Like

That version works! Thank you :slight_smile:

Yes, of course it works :wink:

Don't know if you've seen it, the other macro also has a hidden feature to show you all available http handlers. To see them you just have to run the action named "Or execute this script to get all 'http' apps on your Mac". (Or alternatively enable the surrounding group and run the macro.)
See bottom of post #1 of the other thread.

I already had the needed http handlers, but good to know ty :smiley:

I now added this to my macro that changes the default browser when i change my Proxy settings
due to issues that Chrome has with it.

The above looks terribly complex to me; I just want a hotkey, a macro, batchfile - whatever works - to QUICKLY change default browsers between Firefox and Edge. Which part of the above is relevant to my aim ?

Hey Joseph,

Welcome to the forum!   :smile:

Apple has not made this a simple task to script. While it's possible to do it with Keyboard Maestro running some Swift code, you have to contend with an intrusive dialog that asks you if you're sure you want to switch.

You might be better off with Choosy:

https://www.choosyosx.com/

A freeware alternative (not simple to use):

https://github.com/johnste/finicky

-Chris

1 Like

I had no idea that Keyboard Maestro was Apple.
I run Win10 PCs – is Choosy applicable to that ?

Joe

Keyboard Maestro does only work on macOS, correct. However, there's no better time to switch to a Mac.  :stuck_out_tongue:

Otherwise, for Windows this link might help you?

It refers to

which is apparently not being actively maintained or developed. YMMV.

Hope you can find something that works out well for you.

Thank you.
Joe

Hey Joseph,

No, there's not a version of Choosy available for Windows.

You may want to investigate the following Windows Automation Tools:

Microsoft Power Automate

https://www.autohotkey.com/

They may not do what you want, but they might change the way you use Windows.

-Chris