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

Use AppleScripts to send URLs from browser to browser Web Browsers
I finally got around to generalizing the ability to "open URL in $browser" using a single keystroke -- that is, while running browser X, open the currently-viewed URL in browser Y. The services menu, unfortunately:
  • requires the current URL be highlighted
  • doesn't seem to work with some browsers
Other built-in methods were either inconsistent or incomplete, so I went with AppleScript, based on the five browsers I use (Camino, Firefox, Opera, Safari, and the lovely ELinks).

Part 1: The Scripts

Here's the AppleScript that handles grabbing the current URL and then passing it to the browser of choice:
tell application "System Events"
  set myApp to name of first application process whose frontmost is true
  if myApp is "Camino" then
    tell application "Camino"
      set myURL to URL of window 1
    end tell
  else if myApp is "firefox-bin" then
    tell application "Firefox"
      set myURL to «class curl» of window 1
    end tell
  else if myApp is "Opera" then
    tell application "Opera"
      set myInfo to GetWindowInfo of window 1
      set myURL to item 1 of myInfo
    end tell
  else if myApp is "Safari" then
    tell application "Safari"
      set myURL to URL of document 1
    end tell
  else
    return
  end if
end tell

do shell script "open -a camino " & quoted form of myURL
(Note: Thanks to this forum thread for the Firefox solution.)

I made four copies of the script, substituting camino in the final line with the appropriate browser.

For ELinks, the entire line should be replaced with this:
tell application "Terminal"
  activate
  do script "elinks " & quoted form of myURL
end tell
Also, Opera 9.x isn't AppleScript enabled by default (for now), so you have to add the following to its info.plist file:
<key>NSAppleScriptEnabled</key>
<string>Yes</string>
Finally, going from ELinks to a GUI browser is best handled within elinks itself. Here's the lua code to add to hooks.lua, e.g.:
function guiBrowser ()
  os.execute("open " ..current_url ())
end

bind_key ("main", "X", guiBrowser)
Which will open in your default browser.

Part 2: Key Bindings

I used QuickSilver to bind these scripts to unique keystrokes (Butler, etc. would probably work equally well). FastScripts (Lite) allows application-specific shortcuts if you don't want to use global ones; just rewrite the scripts accordingly (the free Lite version has a 10-shortcut limit, so the CamiScripts plug-in for Camino will come in handy here).

[robg adds: I tested the Camino script with Butler, and it worked fine -- with Safari open, pressing my defined hotkey loaded the current URL into Camino.]
    •    
  • Currently 2.83 / 5
  You rated: 3 / 5 (6 votes cast)
 
[16,659 views]  

Use AppleScripts to send URLs from browser to browser | 12 comments | Create New Account
Click here to return to the 'Use AppleScripts to send URLs from browser to browser' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Use AppleScripts to send URLs from browser to browser
Authored by: sophistry on Mar 29, '06 08:58:15AM

If you are already using Quicksilver I suggest you check out the Proxy Objects available in beta mode. Go to QS prefs and choose Application pane and check "enable advanced features" beta. Then, go to Catalog QuickSilver and choose Proxy Objects. Then go to Actions URLs and choose Open URL With.

Current Web Page is a proxy object that you can hand off to any other program by using Open URL With action and then choose the app you want. Like this:

Activate QS
Type currw (to get the current web page proxy object)
Tab
Type ow (to get Open URL with action)
Tab
Type Fire (to get firefox)
Return



---
soph



[ # ]
Use AppleScripts to send URLs from browser to browser
Authored by: ra5ul on Mar 29, '06 10:25:31AM

no, this only works from safari -> another browser.



[ # ]
Use AppleScripts to send URLs from browser to browser
Authored by: ichweissnicht on Feb 02, '07 05:39:10AM

Yet another thing that Quicksilver does that I didn't know how to do. I don't mind writing, or in this case copying, Applescript, but QS once again shows off and saves me the trouble.

I swear I'm more amazed by that app everyday.



[ # ]
Use AppleScripts to send URLs from browser to browser
Authored by: kL on Mar 29, '06 01:57:01PM

I can drag addressbar by icon in it in all my browsers. Usually I just drag tab from Opera onto dock icons - works great. No scripts needed.



[ # ]
Use AppleScripts to send URLs from browser to browser
Authored by: stealthgeek on Mar 30, '06 06:47:40AM

Hey! I didn't know you could do that. Seems to me like very close to an ideal solution. Thanks for the tip!

---
Stealthgeek



[ # ]
Use AppleScripts to send URLs from browser to browser
Authored by: macnai on Mar 30, '06 06:16:35AM

Can this be made to work with Internet Explorer for those rare occasions nothing else will do...I had a play with the script but no joy (if I'm honest I was just stabbing in the dark). Thanks



[ # ]
Use AppleScripts to send URLs from browser to browser
Authored by: ra5ul on Mar 30, '06 07:14:04AM
i purposely excluded i.explorer, but here you go:

from $browser -> explorer

...
do shell script "open -a 'internet explorer' " & quoted form of myURL

from explorer -> $browser

...
tell application "Internet Explorer"
	set myURL to do script "window.location.href"
end tell
...


[ # ]
Use AppleScripts to send URLs from browser to browser
Authored by: macnai on Apr 13, '06 08:31:08AM

Thanks for your help here. I still can't get any of the scripts in this whole to work with IE. In IE, I can get the URL to open in other browsers, but I can't get other browsers URL to launch in IE. I'm really no good at scripting either so I'm no help. TIA



[ # ]
Use AppleScripts to send URLs from browser to browser
Authored by: adamh on Mar 30, '06 10:32:27PM
Great script.

I've simplified it a bit and put it into one script so you can choose the brower(s) to target from a dialog, instead of having to bind so may keys to seperate scripts.
set browserTargets to {"camino", "safari", "internet explorer", "firefox", "opera"}

tell application "System Events"
	set myApp to name of first application process whose frontmost is true
	if myApp is "Camino" then
		tell application "Camino" to set myURL to URL of window 1
	else if myApp is "firefox-bin" then
		tell application "Firefox" to set myURL to «class curl» of window 1
	else if myApp is "Opera" then
		tell application "Opera" to set myURL to item 1 of (GetWindowInfo of window 1)
	else if myApp is "Safari" then
		tell application "Safari" to set myURL to URL of document 1
	else if myApp is "Internet Explorer" then
		tell application "Internet Explorer" to set myURL to do script "window.location;"
	else
		return
	end if
end tell

tell application myApp
	activate
	set targetBrowser to choose from list browserTargets with title "Open URL in Browser" with prompt myURL with multiple selections allowed without empty selection allowed
end tell

if (targetBrowser is not false) then
	repeat with i from 1 to count of targetBrowser
		set tb to item i of targetBrowser
		do shell script "open -a " & quoted form of tb & " " & quoted form of myURL
	end repeat
end if

Couldn't get the opera code to work on my machine (v8.52) even with plist mod though?

[ # ]
Use AppleScripts to send URLs from browser to browser
Authored by: ra5ul on Mar 31, '06 08:01:17AM
i've only tested it on opera 9.x (on tiger).

i forgot to mention that the dictionary for opera (and i.explorer 5.2.3, which also required the .plist mod.) didn't show up until i rebuilt the launchservices database. you could always give that a try.

[ # ]

Use AppleScripts to send URLs from browser to browser
Authored by: halbtuerke on Jan 24, '07 10:10:32AM

I tested both scripts but none work at all.
Pasted the script into the scripteditor and saved it as script in my scripts folder. What have i possibly done wrong?

Thanks in advance



[ # ]
Use AppleScripts to send URLs from browser to browser
Authored by: ra5ul on Jan 31, '07 11:36:10AM

the scripts use "system events" to determine the frontmost application, so you have to trigger them from something (like quicksilver) that doesn't interfere with the frontmost app.

running it from the finder or the script menu won't work.



[ # ]