February 17, 2023

Redirect links in browser to default browser (using BrowserTamer)

I present here some solutions to redirect links in a browser to a default browser.

Problem description

I use different Browsers with different profiles and a Browser Redirector tool like BrowserTamer.
I would like also from a current browser to open external links with their default (i.e. as defined in BrowserTamer) associated browser.

Solution

Shift Click Redirect (AutoHotkey)

A solution can be implemented in AutoHotkey e.g. when I Shift+Click on a link it will open the link with BrowserTamer.

See Gist code example below:

This is implemented in the NWS PowerTool.

Normal Click Redirect (Custom Protocol+Redirector Extension)

Alternatively you can implement a solution using the Redirector extension and a custom BrowserTamer protocol: this will open the links with BrowserTamer by normal click on the link.

I couldn't find an easy way to implement a protocol handler directly that will strip the prefix <protocolname>: before the url. The easiest way for me was to implement a quick AutoHotkey file to do so.

(I have tried %%%%1:~3% instead of %1 but because of % inside % is doesn't work. I would need multiple lines like url = %1 "%url:~3%" instead of %1 but here again didn't find how to pass multiple commands and handle : in : for the string replace.)

Command must be an .exe. 

VBS Script

I have tried a .vbs as implemented below but the command key isn't imported (Command must be an .exe).

Url = Replace(WScript.Arguments(0),"bt:","")
RunCmd = "bt.exe "  & """ & Url & """
CreateObject("Wscript.Shell").Run RunCmd, 0, True

Using Wbscript.exe to call the .vbs file (as mentioned here)  like this:

[HKEY_CLASSES_ROOT\<name>\shell\open\command]
@="C:\\Windows\\System32\\WScript.exe \"C:\\Program Files\\<name>.vbs\" \"%1\""
would have a been close to work but it got blocked by the malware protection software. (Maybe it works for you.)

AutoHotkey script

AutoHotkey Script for redirector protocol (Filename: btp.ahk) is very simple:

btp(A_Args[1])

btp(sUrl){
    sUrl:=RegExReplace(sUrl,"^bt:","")
    Run, "bt.exe" %sUrl%
} ; eof

Compile the script 
Compile the AHK script to a standalone .exe btp.exe
Place this btp.exe file in the same location as BrowserTamer (Alternatively, you can hard-code the path to "bt.exe" in the AHK script.)

Registry file

You can take as basis the x-bt entry whose path you can find by going to 


Help-> Registry->Copy path to clipboard -> Custom Protocol

The path looks like Computer\HKEY_CURRENT_USER\Software\Classes\x-bt


Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\SOFTWARE\Classes\bt]
@="URL:bt"
"URL Protocol"=""

[HKEY_CURRENT_USER\SOFTWARE\Classes\bt\shell]

[HKEY_CURRENT_USER\SOFTWARE\Classes\bt\shell\open]

[HKEY_CURRENT_USER\SOFTWARE\Classes\bt\shell\open\command]
@="\"C:\\Users\\thierry.dalon\\PortableApps\\BrowserTamer\\btp.exe\" \"%1\""

Adapt the path in this file to your BrowserTamer installation folder bt.exe location.

Save as .reg file

Import registry file in regedit.

Browser Redirector Extension

In your browser (e.g. Chrome) configure the Redirector Extension by using rules that redirect the URL to the bt: protocol.
See example below to redirect all urls.

This allows you to reuse your BrowserTamer redirect configuration (which browser to use) in you current browser.

See also

Registering an Application to a URI Scheme (Windows) | Microsoft Learn

Redirector - Chrome Web Store

Browser Tamer (Tool recommendation) | Thierry Dalon's Blog

SharePoint links incl. Stream automatically redirected to Microsoft Edge browser | Thierry Dalon's Blog

No comments:

Post a Comment