10.8: Open a specific browser based on the URL

Aug 27, '14 07:00:00AM

Contributed by: tom_sep

Usually I want to open Gmail in Chrome and URLs pointing to my development server in Firefox. For everything else I use Safari.

There is this nifty free app called LinCastor that enables you to register your own handler for an URL. Although it had beed designed to register your own non-standard URL schemes, it can intercept standard http and https as well.

In LinCastor (which you need to double-click twice to fully open for editing):

Paste the following code in, (replacing the stub code at the bottom):
on handle_url(args)
  if (|URL| of args starts with "https://mail.google.") then
    tell application "Google Chrome"
      open location |URL| of args
    end tell
  else if (|URL| of args starts with "http://") then
    tell application "Firefox"
      open location |URL| of args
    end tell
  else
    tell application "Safari"
      open location |URL| of args
    end tell
        end
       return 1
end
Obviously you should customize the code to suite your own specific needs. You can validate the script right in LinCastor before saving/activating it. I use the same mechanism to launch 'site specific browsers apps' created by Fluid. For example I have a JIRA app wrapper which looks for anything staring with http://issues.

[crarko adds: I tested this, and it works as described. LinCastor requires OS X 10.8 or later. I tried it in 10.10 beta 2, and it also worked there. There's not much documentation for it, so tinker around a bit to get the result you want.]

Comments (9)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20131022070219858