Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

iRock1

macrumors 65816
Original poster
Apr 23, 2011
1,083
145
Right now I have to go through Develop > Open Page With > Google Chrome. What I need though is to do the same using a keyboard shortcut.

One option would be assigning a keyboard shortcut to that menu in the Keyboard Preferences Pane. However, the menu includes the app version, so I'd need to modify the keyboard shortcut every time Google Chrome updates.

Maybe I could use the AppleScript Editor or Automator to create a new service and then use FastScripts? If so, what should I write? Because my knowledge of scripting is almost zero. :p
 
This Applescript will open the front Safari window in a new Chrome tab.

I launch it from Alfred as a "workflow", but Fastscript should do the trick also.

Code:
if application "Safari" is running then
	tell application "Safari"
		try
			set currentSafariURL to URL of current tab of front window
			set pageName to name of current tab of front window
		on error
			return "There are no pages open in Safari at the moment"
		end try
	end tell
	
	tell application "Google Chrome"
		activate
		
		# If Chrome has no windows open make a new window
		if (count of windows) is 0 then make new window
		set currentChromeURL to URL of active tab of front window
		
		# Don't do anything if the page is already open in Chrome
		if currentChromeURL is not currentSafariURL then
			
			# If the active tab is in use make a new tab
			if currentChromeURL is not "chrome://newtab/" then
				make new tab at end of tabs of front window
			end if
			
			# Open the URL from Safari
			set URL of active tab of front window to currentSafariURL
			
		else
			return "The current Safari tab is already open in Chrome"
		end if
	end tell
	
	# Enable the following line to post notifications after sending URLs to Chrome
	--return "Opening '" & pageName & "' in Chrome"
else
	return "Safari is not open at the moment"
end if

Credit to the author of the Alfred workflow here.
 
This Applescript will open the front Safari window in a new Chrome tab.

I launch it from Alfred as a "workflow", but Fastscript should do the trick also.

Code:
if application "Safari" is running then
	tell application "Safari"
		try
			set currentSafariURL to URL of current tab of front window
			set pageName to name of current tab of front window
		on error
			return "There are no pages open in Safari at the moment"
		end try
	end tell
	
	tell application "Google Chrome"
		activate
		
		# If Chrome has no windows open make a new window
		if (count of windows) is 0 then make new window
		set currentChromeURL to URL of active tab of front window
		
		# Don't do anything if the page is already open in Chrome
		if currentChromeURL is not currentSafariURL then
			
			# If the active tab is in use make a new tab
			if currentChromeURL is not "chrome://newtab/" then
				make new tab at end of tabs of front window
			end if
			
			# Open the URL from Safari
			set URL of active tab of front window to currentSafariURL
			
		else
			return "The current Safari tab is already open in Chrome"
		end if
	end tell
	
	# Enable the following line to post notifications after sending URLs to Chrome
	--return "Opening '" & pageName & "' in Chrome"
else
	return "Safari is not open at the moment"
end if

Credit to the author of the Alfred workflow here.

It works wonderfully. I just saved it as a script, then assigned it a keyboard shortcut with FastScripts and voilâ!

Thanks.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.