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.