Mar 29, '06 06:24:00AM • Contributed by: ra5ul
- requires the current URL be highlighted
- doesn't seem to work with some browsers
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.]
