Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

10.8: Open a specific browser based on the URL Apps
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):
  • Add a new URL scheme
  • Choose AppleScript handler
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.]
    •    
  • Currently 1.04 / 5
  You rated: 2 / 5 (231 votes cast)
 
[11,531 views]  

10.8: Open a specific browser based on the URL | 9 comments | Create New Account
Click here to return to the '10.8: Open a specific browser based on the URL' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
10.8: Open a specific browser based on the URL
Authored by: peterpk on Aug 27, '14 08:51:14AM

Choosy (http://www.choosyosx.com) can do similar things, and it doesn't require Applescripting (though the advanced features do need an understanding of regular expressions).



[ Reply to This | # ]
10.8: Open a specific browser based on the URL
Authored by: asscher on Aug 28, '14 05:17:18AM

It doesn't work as described.

Please elaborate to how you succeeded with LinCastor.
When I substitude your code in LinCastor FireFox will start immediately (should not happened )
When adding URL's in iCal or in TextEdit for example "https://mail.google." I will get "There is no application set to open the URL...."
I aim also using Fluid application however if this will work it will be nice.

Hope to get explanation.



[ Reply to This | # ]
10.8: Open a specific browser based on the URL
Authored by: mcoyle1960 on Aug 28, '14 07:42:37PM

Ugh. I really want this to work, but it's not. I want Safari to handle only Facebook, fo Firefox is my default browser and I want Safari to open for Facebook notifications.

Here is my script after validation:

on handle_url(args)
if (|URL| of args starts with "https://www.facebook.") then
tell application "Safari"
open location |URL| of args
end tell
end if
return 1
end handle_url

When I click on a facebook webloc or a notification, it still opens Firefox. Suggestions?



[ Reply to This | # ]
10.8: Open a specific browser based on the URL
Authored by: crarko on Sep 04, '14 03:08:24AM

Let me re-check this to see if anything got mangled in the hint. It seems to me I did have to adjust a few things to make it work on my Mac.



[ Reply to This | # ]
10.8: Open a specific browser based on the URL
Authored by: tom_sep on Sep 10, '14 11:52:55PM

Hi, I tested it on 10.9 and it does work as described - very strange (sorry, not that much helpful, I know)

If you want to intercept HTTP/HTTPS make sure the registered scheme says http,https. You may also try it with your own scheme (e.g. test-http) to make sure it works first.

Also, make sure the AppleScript tab is active when you hit Save and Activate - the active tab chooses what handler to run no matter what you write in

If you still have a problem, don't be afraid to contact the author. He tends to be very responsive.



[ Reply to This | # ]
10.8: Open a specific browser based on the URL
Authored by: ms_t_rie on Sep 04, '14 03:23:16PM

Normally, I open my default browser and go to bookmarks. There's only a few I'd want to open in a different browser. Would this work for bookmarks that exist in the browser you are using?



[ Reply to This | # ]
10.8: Open a specific browser based on the URL
Authored by: jcmurphy on Sep 07, '14 01:34:02PM

I could not make this work either. I got a "handler not found" type error. When clicking on any "http:" type link, nothing would launch. No Safari, Firefox or Chrome. I had to uninstall to get everything working again. I am using the current version of Mavericks and the current version of all three browsers. Does this only work for 10.8?



[ Reply to This | # ]
10.8: Open a specific browser based on the URL
Authored by: tom_sep on Sep 11, '14 12:31:21AM

Maybe the handle's scheme doesn't match the link scheme (?)
Make sure the registered scheme is set exactly to 'http' (not HTTP or http:)



[ Reply to This | # ]
10.8: Open a specific browser based on the URL
Authored by: jcmurphy on Sep 15, '14 09:47:48AM

i did give this a try again but ran into the same issues. The AppleScript I used was exactly as above (no changes whatsoever). All http & https web pages went right to Safari. Links to https://mail.google.com did the same.

I also tried test-http, test-https but that was a disaster. LinCastor went into a forever loop quickly adding hundreds of LinCastor generated notification windows (similar to its small notification window at startup.) I could not force quit anything and had to lean on the power button to shut-down the computer.

I will contact the author.



[ Reply to This | # ]