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

AppleScript to open current Safari page in Google Chrome via LaunchBar or TextExpander Apps
We ran a hint last month about opening the current Safari page in Chrome, but Padraic Renaghan came up with a nice AppleScript that he uses to open the page in Chrome via a LaunchBar action.

property theURL : ""
tell application "Safari"
	set theURL to URL of current tab of window 1
end tell

if appIsRunning("Google Chrome") then
	tell application "Google Chrome"
		if (count of (every window where visible is true)) is greater than 0 then
			-- running with a visible window, ready for new tab
		else
			-- running but no visible window, so create one
			make new window
		end if
	end tell
else
	tell application "Google Chrome"
		-- chrome app not running, so start it
		do shell script "open -a \"Google Chrome\""
	end tell
end if

-- now that we have made sure chrome is running and has a visible
-- window create a new tab in that window
-- and activate it to bring to the front
tell application "Google Chrome"
	tell front window
		make new tab with properties {URL:theURL}
	end tell
	activate
end tell

on appIsRunning(appName)
	tell application "System Events" to (name of processes) contains appName
end appIsRunning
He got the original idea from another AppleScript to open Chrome via TextExpander , created by Tim Arnold. Here's his script:
property theURL : ""
tell application "Safari"
	set theURL to URL of current tab of window 1
end tell
if appIsRunning("Google Chrome") then
	tell application "Google Chrome"
		make new window
		set URL of active tab of window 0 to theURL
		activate
	end tell
else
	tell application "Google Chrome"
		do shell script "open -a \"Google Chrome\""
		set URL of active tab of window 0 to theURL
		activate
	end tell
end if

on appIsRunning(appName)
	tell application "System Events" to (name of processes) contains appName
end appIsRunning
With the former, you save the script with any name you want, and type an abbreviation in LaunchBar to activate it. With the second script, you set a TextExpander abbreviation to run the script, and just type the abbreviation. Both of these scripts could be used in other applications: other launchers like LaunchBar, and other snippet expanders like TextExpander, as long as they support AppleScripts. Both are nice ways to quickly open a Safari page in Chrome.
    •    
  • Currently 3.50 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (4 votes cast)
 
[5,909 views]  

AppleScript to open current Safari page in Google Chrome via LaunchBar or TextExpander | 7 comments | Create New Account
Click here to return to the 'AppleScript to open current Safari page in Google Chrome via LaunchBar or TextExpander ' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
AppleScript to open current Safari page in Google Chrome via LaunchBar or TextExpander
Authored by: RussellK on Jul 24, '12 07:55:50AM

Pardon my ignorance, but why not just enable the "Develop" menu in Safari (unless this is now enabled by default?), and then use that menu to: Develop >> Open Page With >> [choose desired browser from list].

That's what I've been doing for as long as I can remember to open current pages from Safari in alternate browsers...



[ Reply to This | # ]
AppleScript to open current Safari page in Google Chrome via LaunchBar or TextExpander
Authored by: whshep on Jul 24, '12 08:23:40AM

Speed. LaunchBar is faster, easier.



[ Reply to This | # ]
AppleScript to open current Safari page in Google Chrome via LaunchBar or TextExpander
Authored by: felibb on Jul 24, '12 10:28:04AM

There is actually a reason for that: keyboard support breaks every time Chrome updates. I used to have a custom shortcut in System Preferences, but since the menu item in "Develop Open Page With" includes Chrome's full version number, the shortcut becomes invalid after a Chrome update is installed. And Chrome updates frequently and silently (which, in and of itself, is a good thing). So I resorted to using a Service with AppleScript.

Now I am going to try the OP's new one.



[ Reply to This | # ]
AppleScript to open current Safari page in Google Chrome via LaunchBar or TextExpander
Authored by: ale82to on Jul 24, '12 11:28:33AM

ehi excellet tip it saves me so much time!!??
is it possible to do a similar one for hudtube a little app for waching youtube video?
thanks!



[ Reply to This | # ]
AppleScript to open current Safari page in Google Chrome via LaunchBar or TextExpander
Authored by: Lri on Jul 24, '12 11:47:42AM

This script should behave more or less the same way:

tell application "Safari" to set u to URL of document 1
do shell script "open " & quoted form of u & " -a Google\\ Chrome"

It won't open an additional empty tab in some cases where the script in the submission would though.



[ Reply to This | # ]
AppleScript to open current Safari page in Google Chrome via LaunchBar or TextExpander
Authored by: ericdano on Jul 24, '12 12:28:41PM

And if one uses Alfred.........how does one do this?



[ Reply to This | # ]
AppleScript to open current Safari page in Google Chrome via LaunchBar or TextExpander
Authored by: Lri on Jul 24, '12 02:06:31PM

You can add an AppleScript extension by clicking the plus button in the Extensions tab. Since the script doesn't need any parameters, you don't even need the alfred_script handler.

To give a global shortcut to an AppleScript, you can save it somewhere with AppleScript Editor and then drag it to the Hotkeys tab.



[ Reply to This | # ]