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

Open external links in currently running browser Web Browsers
If you are using multiple browsers, and are annoyed by Safari (or your designated preferred browser) popping up while using a different browser, this hint can remove that annoyance.

I'm a web developer, and while my main browser is WebKit, I also have Opera, Chrome and Firefox installed. If I'm using Opera and click a link in Mail, that link will open in Safari. So I wind up with two running browsers, or having to copy the URL over to Firefox manually. Not cool.

I have figured out a way to make an AppleScript 'proxy' app that delegates URLs to the browser that is currently running, no matter which is set as the default. Paste the following code into AppleScript Editor:
on open location the_url
  tell application "System Events"
    set browser_apps to the name of every process whose visible is true
    if "Opera" is in browser_apps then
      tell application "Opera"
        open location the_url
        activate
      end tell
    else if "firefox-bin" is in browser_apps then
      tell application "Firefox"
        open location the_url
        activate
      end tell
    else if "Google Chrome" is in browser_apps then
      tell application "Google Chrome"
        open location the_url
        activate
      end tell
    else
      tell application "WebKit"
        open location the_url
        activate
      end tell
    end if
  end tell
end open location
Modify the above as needed to reflect your own suite of browsers, then save this script as an application bundle somewhere. Next, you need modify a bit of the application bundle you just created.

Drill down into the app by Control-clicking on it, and choosing Show Package Contents from the pop-up menu. Navigate into Contents and open Info.plist in your favorite text editor, and paste this code near the end:
<key>CFBundleIdentifier</key>
  <string>nl.pepijndevos.urlhandler</string>
  <key>CFBundleURLTypes</key>
  <array>
    <dict>
      <key>CFBundleURLName</key>
      <string>Applescript urls</string>
      <key>CFBundleURLSchemes</key>
      <array>
        <string>http</string>
        <string>https</string>
        <string>file</string>
      </array>
      <key>LSIsAppleDefaultForScheme</key>
      <true/>
    </dict>
  </array>
Now run the application -- nothing will happen, but this will register the app with Launch Services.

The only thing that remains to be done now is open Safari, go to the General tab in its Preferences, and set your new AppleScript as the default browser.

[crarko adds: This hint originally appeared on the author's blog. You can also download a final version of this app, either from the linked blog entry, or mirrored here on Mac OS X Hints [28KB]. If you download the application, note that you'll need to dig into the package and modify the source script to reflect the browsers you use. I tested this one, and it worked as described.]
    •    
  • Currently 3.79 / 5
  You rated: 3 / 5 (24 votes cast)
 
[9,974 views]  

Open external links in currently running browser | 15 comments | Create New Account
Click here to return to the 'Open external links in currently running browser' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Open external links in currently running browser
Authored by: kentmartin on May 07, '10 09:13:28AM

Brilliant idea. Love it... will fire it up as soon as I get home.

Well done.



[ Reply to This | # ]
Open external links in currently running browser
Authored by: ehunt123 on May 07, '10 09:25:27AM

why bother?

http://sites.google.com/site/tesseractsoftware

or choose whisley

few others floating around out there and choosey is a paid solution



[ Reply to This | # ]
Open external links in currently running browser
Authored by: Andrew J Freyer on May 07, '10 10:12:54AM

Personally, I think this hint is great. The other solutions that you link to require user interaction - this hint does not.

Plus, this is an excellent way to demonstrate how to register an applescript app with launch services.

---
Easier location-based computing: with Airport Location, app for 10.6. It's an early Beta, so please report bugs!

http://airportlocation.blogspot.com



[ Reply to This | # ]
Re: Open external links in currently running browser
Authored by: Uncle Asad on May 07, '10 02:17:06PM

I've found that on some versions of Mac OS X, the AppleScript app must also have a unique bundle signature (i.e. creator code, aka the CFBundleSignature key in the app's Info.plist *and* the second set of four characters in the AppName.app/Contents/PkgInfo file) in order for the default app setting to stick.

I've been doing this for a while, and my apps supported back to 10.3.9 at the time they were written, so I can't say for certain where that bundle signature was required and where it might have stopped, but it's important to keep that in mind. (It's also good practice to do so to prevent unexpected collisions, anyway, but it seems necessary when registering protocols or file types/extensions with LaunchServices.)



[ Reply to This | # ]
Open external links in currently running browser
Authored by: cyberdork33 on May 07, '10 09:30:50AM

I hide applications quite a bit, so the 3rd line in the script makes this not work the way I want to. I replaced it instead with

<code>set browser_apps to the name of every process whose background only is false</code>

This filters out all the background apps and ignores whether the browser is hidden or not.



[ Reply to This | # ]
Open external links in currently running browser
Authored by: pepijndevos on May 07, '10 10:31:32AM

Thanks for the positive reactions :)
For me this is one of those things I did not knew I needed, but now I can't live without it anymore :D

@crarko
I was wondering why it took so long for my hint to appear. It seem you did some decent editing, well done!
I'm not a native speaker, do you have some hints to improve my own writings?



[ Reply to This | # ]
Open external links in currently running browser
Authored by: crarko on May 07, '10 01:38:09PM

Like everything else, keep practicing!

~Craig



[ Reply to This | # ]
Open external links in currently running browser
Authored by: foolio on May 07, '10 10:52:36AM

What happens if you have multiple browsers running? Which one does it choose?



[ Reply to This | # ]
Open external links in currently running browser
Authored by: aubreyapple on May 10, '10 10:00:19AM

It picks the first one on the list which is 'visible'. You determine the order by the order in the script. I tried removing the visible limitation and it worked then for hidden browsers, again in the order of the script.



[ Reply to This | # ]
Open external links in currently running browser
Authored by: Hindemith on May 08, '10 04:20:56AM

Wow, you've solved a long existing issue for me pepijndevos - thanks a lot !! I really love this site :))

hindemith



[ Reply to This | # ]
Here's an application which does this and more
Authored by: withdave on May 08, '10 04:18:09PM

I've written an Applescript Application which downloads a DNS blocking file from the net to block over 16,000 domain names via your /etc/hosts. You can easily revert it back, add your own blocks, ignore specific blocks from the net file and run automatically at login to check for an updated list. It preserves and keeps the original Apple /etc/hosts at the front including any hand-added changes you have or might make in the future. I've found my web browsing runs some 20% faster after using this app.

Fetch it at www.bytecodes.com/Super_Ad_Blocker.zip. The XCode source is there under the name Super_Ad_Blocker_Source.zip. It's all GNU copyrighted so feel free to share and modify.



[ Reply to This | # ]
Open external links in currently running browser
Authored by: bookmarkdofollow on May 09, '10 12:19:00PM

Modify the above as needed to reflect your own suite of browsers.
I'll try. Thank you.



[ Reply to This | # ]
-
Authored by: tice on May 09, '10 09:41:15PM

wrong topic.. can't delete...

Edited on May 09, '10 09:43:32PM by tice



[ Reply to This | # ]
Opening in the Frontmost Browser
Authored by: zaudragon on May 15, '10 02:53:34PM

This is one of the most useful hints I've read here by far! My only gripe was that the link would open in the first browser in the if-else block, instead of opening in the frontmost browser.

So, I made my own version of the script that does just that, using a helper executable which lists all your applications in order from front to back (like when you get when you press cmd+tab).

It's here if anyone wants it: http://www.mediafire.com/?ntm5koymvtd

Note that the list of browsers it allows you to open in is listed at the top of the script, and you can also set a "default" browser, i.e. the one it opens if there is no currently running browser.



[ Reply to This | # ]
Trouble under 10.7
Authored by: afb on Nov 14, '11 04:50:22AM

For those who might be having trouble getting this to work on Lion, perhaps a solution:

When saving the script, there is no longer the option 'Application Bundle' (as far as I can see), 'Application' will do, but 'Stay Open' must be checked.

Also, it seems the script cannot be edited after the application is initially saved, neither by opening the app in Script Editor, nor by editing just .../Contents/Resources/Scripts/main.scpt.

The dock icon can be hidden by adding LSUIElement.

Edited on Nov 14, '11 05:05:46AM by afb



[ Reply to This | # ]