open current url in chrome

Sharing and discussing custom actions for LaunchBar

open current url in chrome

Postby mbotta » Wed Mar 16, 2011 12:31 pm

if you've been following the discussions around flash-less browsing with contributions from john gruber http://daringfireball.net/2010/11/flash_free_and_cheating_with_google_chrome, you may have come across this article on TUAW, "Use AppleScript to open current Safari URL in Google Chrome" - http://www.tuaw.com/2011/03/14/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"
      activate
      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
      else
         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
   else
      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).

cheers,

mbotta
mbotta
 
Posts: 1
Joined: Wed Mar 16, 2011 12:05 pm

Re: open current url in chrome

Postby manfred » Thu Mar 17, 2011 12:48 pm

Dear mbotta,

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

Thanks for sharing.
manfred
Objective Development
Objective Development
 
Posts: 553
Joined: Sat Jul 31, 2010 9:47 am
Location: Vienna


Return to LaunchBar Actions

Who is online

Users browsing this forum: No registered users and 3 guests