views:

75

answers:

2

I'm new to use Applescript to create services in Snow Leopard. I found myself often trying to open a link in Safari with Firefox. I know there are ways to open a page url with FF but I want to open any link inside a page with FF. I think using Applescript to create a service might be a good idea and so far I found this:

openFirefoxURL("http://www.apple.com/")

on openFirefoxURL(x)
   return do shell script "open -a Firefox" & space & quoted form of x
end openFirefoxURL

This creates a new tab in FF nicely. Any advice to adapt it to open a link on a page?

UPDATE: I found a solution through trial and error:

tell application "Safari"
    set myURL to (do JavaScript "(getSelection().anchorNode.parentNode.href)" in document 1)
end tell

do shell script "open -a Firefox" & space & myURL

Now that the script serves my purpose, I don't know if there are better ways to do it, e.g. getting the selection via Applescript rather than javascript. Let me know if you have better solutions. Thanks!

A: 

I'm not sure if I entirely understand what you are trying to do, but if you wish to use Firefox as your default browser, then you don't need Applescript. Just go into Safari, open Preferences, then select Firefox as the default browser at the top of the first tab.

Philip Regan
I prefer Safari as my main browser. Thanks for the replay anyway.
lai
+1  A: 

You don't need a special program to do this. Safari already does it. You have to first enable the "Develop" menu in Safari. Go to Safari's preferences, go to the advanced section, and check the box at the bottom called "Show Develop menu in menu bar". Now that you have the Develop menu, you can open any page from Safari in another browser by going to Develop --> Open Page With menu.

So doing that will open the current page in Firefox, then just click on whatever link you want in Firefox.

regulus6633
The Dev "Open Page With" menu is not what I need here. I want a contextual menu option "Open link in Firefox" when I right click a link on a page. This way I dont have to open my current page in FF and then click the link to get what I want. It saves one extra step compared to the Dev Open Page way.
lai
"I want a contextual menu option" Then you are going to have to write an extension for Safari if one doesn't exist.
Philip Regan