Thursday, March 20, 2014

Efficiently Using Multiple Browsers (with a single key press)

Maybe I’m weird, or maybe my job has more requirements than others, but I use Google Chrome, and Microsoft Internet Explorer interchangeably.  I know web developers have this problem, perhaps they’ve already worked out a work flow, but I wasn’t able to find one.  Ultimately for things that are work related, I want to open those in Internet Explorer, and personal browsing, I want to use Google Chrome.  While we all have our reasons for using one browser over another (I have mine), if you want to use both, there was no really good way…

So I had a friend teach me how to write my own browser

Ok, ok, I didn’t technically write my own browser, that would take a lot of work, but what I did do is build a Browser Proxy.  The Browser Proxy is the default Browser on my PC, and all it does, is validate if a key is pressed (“Left Shift” to be exact) and either launch IE or Chrome based on that key.  This means for me now, “Click” is to open in IE and “Shift+Click” is to open in Chrome!

Here’s how I did it
First, you need AutoHotKey, which I’ve written about before.  You can use it have an always-on scripting engine running to help you control Windows, or to create scripts and turn them in executable, which is what we’re going to do here.  So get that installed on your PC.
Second, Choose your actual “Default Browser” in Windows.  I made Internet Explorer default because people send me work related links in Lync, Email, and they are scattered all through documents and such, so it makes sense to make IE default for me.  This means that without the SHIFT key down, IE will be used.
Third, we need to create what I call “Browser Proxy” executable, This is going to be a bit more complicated, to get you started, My friend and I have created the browser .ahk file (AutoHotKey script) and installer .reg file (think of this as associations for your application so Windows can find it).  Download the package here, (virus scan it, because you should virus scan any weird .zip file you download from the Internet), and then unzip it.  You’ll find 3 files, one of which is a readme and you can figure that out.
Crack open the BrowserProxy.ahk in Notepad or your favorite editor, it looks like this:
GetKeyState,State,LShift
IfEqual,State,U
{
    ; Shift Key up -- launch IE
    Run,"C:\Program Files (x86)\Internet Explorer\iexplore.exe" -nohome "%1%"
}
Else
{
    ; Shift Key down -- launch Chrome
    Run,"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" "%1%"
}
Validate the paths for both Internet Explorer and Chrome. Change the paths as appropriate.  You can also chose to use a different key, like if you wanted the Left CONTROL button to be the key you use, change the “LShift” in bold above to “LControl”.  In fact you can choose whatever key you want (here is the list).
Once you’ve got the script validated, save it and then since you now have AutoHotKey installed, you right click on the script and choose Compile Script.
Compile Script
This produces a BrowserProxy.exe in the same directory. I copied this to "C:\Program Files (x86)\BrowserProxy\BrowserProxy.exe" (and agreed to the UAC prompt). You can put this anywhere, but more updates will be required in the .reg file which we’re going to use next.
Now we need to import the BrowserProxy.reg file into your system registry.  Please do feel free to open it in Notepad before importing it (you should always be aware of what you’re putting into your registry), but it does 3 important things
  1. Define the BrowserProxy.exe application under the SOFTWARE section of the registry
  2. Registers that application
  3. Sets up the root classes that the application can handle
If you changed the path of where you put BrowserProxy.exe, you’ll need to update that as well, and mind that you keep double \\ when you put the path in.
Now that your own “Browser” is ready, you need to make it default.  This is how I did it on Windows 8.1
  1. Open the Desktop Control panel (Win+R, type “control”, and click OK)
  2. Click on Programs
  3. select under Default Programs click on Make a file type always open a specific program.
  4. In this dialog, we need to change the default to “Browser Proxy” for “.htm”, “.html”, “.shtml”, “.xht”, “.xhtml”, “FTP”, “HTTP” and “HTTPS”.  Select the item in the list and click on Change program… then select BrowserProxy.exeChange Associations
Once you have configured all 8 defaults, you should be able to immediately start using a CLICK to open in IE and SHIFT+CLICK to open in Chrome!!
Note: Some applications may cache the default browser, in which case they would need to be restarted (My offender: Outlook).  Now you can use two browsers easily without having to do the usual tricks of copying URLs between browser windows, or manually setting default browsers constantly.
Final note: If you are looking for a way to launch Firefox, try changing the launch EXE in the .ahk script to:
{
    ; Shift Key down -- launch FireFox
    Run,"C:\Program Files (x86)\Mozilla Firefox\firefox.exe" -requestPending -osint -url "%1%"
}
For Reference here is the contents of the .reg file:
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Clients\StartMenuInternet\BrowserProxy.EXE]
@="BrowserProxy"

[HKEY_LOCAL_MACHINE\SOFTWARE\Clients\StartMenuInternet\BrowserProxy.EXE\Capabilities]
"ApplicationDescription"="Browser Proxy Application, enables you to switch between IE or Chrome simply by pressing SHIFT when you click"
"ApplicationName"="BrowserProxy"

[HKEY_LOCAL_MACHINE\SOFTWARE\Clients\StartMenuInternet\BrowserProxy.EXE\Capabilities\FileAssociations]
".htm"="BrowserProxyHTML"
".html"="BrowserProxyHTML"
".shtml"="BrowserProxyHTML"
".xht"="BrowserProxyHTML"
".xhtml"="BrowserProxyHTML"

[HKEY_LOCAL_MACHINE\SOFTWARE\Clients\StartMenuInternet\BrowserProxy.EXE\Capabilities\StartMenu]
"StartMenuInternet"="BrowserProxy.EXE"

[HKEY_LOCAL_MACHINE\SOFTWARE\Clients\StartMenuInternet\BrowserProxy.EXE\Capabilities\URLAssociations]
"ftp"="BrowserProxyHTML"
"http"="BrowserProxyHTML"
"https"="BrowserProxyHTML"

[HKEY_LOCAL_MACHINE\SOFTWARE\Clients\StartMenuInternet\BrowserProxy.EXE\DefaultIcon]
@="C:\\Program Files (x86)\\BrowserProxy\\BrowserProxy.exe,0"

[HKEY_LOCAL_MACHINE\SOFTWARE\Clients\StartMenuInternet\BrowserProxy.EXE\shell]
[HKEY_LOCAL_MACHINE\SOFTWARE\Clients\StartMenuInternet\BrowserProxy.EXE\shell\open]
[HKEY_LOCAL_MACHINE\SOFTWARE\Clients\StartMenuInternet\BrowserProxy.EXE\shell\open\command]
@="\"C:\\Program Files (x86)\\BrowserProxy\\BrowserProxy.exe\""

[HKEY_LOCAL_MACHINE\SOFTWARE\RegisteredApplications]
"BrowserProxy"="Software\\Clients\\StartMenuInternet\\BrowserProxy.EXE\\Capabilities"

[HKEY_CLASSES_ROOT\BrowserProxyHTML]
@="Browser Proxy"
"FriendlyTypeName"="Browser Proxy"

[HKEY_CLASSES_ROOT\BrowserProxyHTML\DefaultIcon]
@="\"C:\\Program Files (x86)\\BrowserProxy\\BrowserProxy.exe\",0"

[HKEY_CLASSES_ROOT\BrowserProxyHTML\shell]
[HKEY_CLASSES_ROOT\BrowserProxyHTML\shell\open]
[HKEY_CLASSES_ROOT\BrowserProxyHTML\shell\open\command]
@="\"C:\\Program Files (x86)\\BrowserProxy\\BrowserProxy.exe\" \"%1\""