Page 1 of 1

open current url in chrome

Posted: Wed Mar 16, 2011 12:31 pm
by mbotta
if you've been following the discussions around flash-less browsing with contributions from john gruber, you may have come across this article on TUAW, "Use AppleScript to open current Safari URL in Google Chrome" -

i find that i tend to use netnewswire as often as i do safari, both of which use the system-wide flash instance. this applescript checks which of those two is the frontmost application and opens the current url in chrome. i'm an applescript newbie, so any improvements are more than welcome :)

Code: Select all

tell application "LaunchBar" to hide

tell application "System Events" to set currentApplication to name of 1st application process whose frontmost is true

set currentURL to getCurrentURL(currentApplication)

if currentURL is not "" then
   tell application "Google Chrome"
      if (exists window 1) and (URL of active tab of window 1 is "chrome://newtab/") then
         tell window 1 to set URL of active tab to currentURL
         open location currentURL
      end if
   end tell
end if

on getCurrentURL(currentApp)
   if currentApp = "Safari" then
      tell application "Safari" to set currentURL to URL of current tab of window 1
   else if currentApp = "NetNewsWire" then
      tell application "NetNewsWire"
         set allURLs to URLs of tabs
         set currentURL to item (index of selected tab + 1) of allURLs
      end tell
      currentURL = ""
   end if
   return currentURL
end getCurrentURL

if you use other browsers that use the system-wide flash instance, add your applescript code to getCurrentURL(currentApp).



Re: open current url in chrome

Posted: Thu Mar 17, 2011 12:48 pm
by manfred
Dear mbotta,

I followed John Grubers article too. Great idea to use an AppleScript and LaunchBar for triggering Chrome!

Thanks for sharing.