Skip to content

Instantly share code, notes, and snippets.

@paulirish
Created April 4, 2016 00:24
Show Gist options
  • Save paulirish/d7df1a5ff5d269b9884a9d22461af613 to your computer and use it in GitHub Desktop.
Save paulirish/d7df1a5ff5d269b9884a9d22461af613 to your computer and use it in GitHub Desktop.
open chrome tabs in safari
tell application "Google Chrome"
set tab_list to every tab in the front window
repeat with the_tab in tab_list
set the_url to the URL of the_tab
tell application "Safari" to open location the_url
end repeat
end tell
@paulirish
Copy link
Author

script was borne of this twitter thread: https://twitter.com/paul_irish/status/716765743056969728

to run

grab the file and run this in your shell

osascript open-chrome-tabs-in-safari.scpt

@ashrocket
Copy link

I know this is a stupid question. I thought this was a run-once script. Which I did. But now I periodically get a message about No Application found for Chrome::New Tab.

I'm sure somehow this script is still running in the background, but I can't find it to kill it.

Can you advise how to hunt it down and kill it (I have restarted multiple times)

@o-simardcasanova-net
Copy link

Hi! Great gist. But as I'm not that a cli guy I wrapped it in an Automator app to use it. I released an "app" here: https://github.com/simardcasanova/SendToSafari. Hope it'll help.

@paulirish
Copy link
Author

paulirish commented Jun 27, 2017

@ashrocket AFAIK this is a run-once script, yeah. :) i'm about as n00b at applescript as anyone, so your googling/debugging is a good as mine.

@simardcasanova very cool! thanks

@thagorastos
Copy link

Thanks! Great work/tip!

@davo
Copy link

davo commented Aug 12, 2018

Same thing on the opposite direction, from Safari to Chrome.

tell application "Safari"
	
	set tab_list to every tab in the front window
	
	repeat with the_tab in tab_list
		set the_url to the URL of the_tab
		tell application "Google Chrome" to open location the_url
	end repeat
	
end tell

@Dudemullet
Copy link

Here's a variant to only open the current tab in safari with an optional line to close the tab

tell application "Google Chrome"
	
	set current_tab to active tab in the front window
	set the_url to the URL of current_tab
	tell application "Safari" to open location the_url
	
	# Uncomment the next line to close tab after opening in Safari
	# tell current_tab to close
end tell

@aman3011
Copy link

how can I do this for one window at a time, so safari opens multiple windows as well?

@JCDC85
Copy link

JCDC85 commented Jan 8, 2020

Thanks for this, it is exactly what I have been looking for. I am surprised it was so hard for me to find until I happened upon this thread.
So I was able to make an Automator app with the three scripts posted here above but when I try and adapt it to a single safari tab sent to chrome I get a "syntax error: Expected end of line, etc. but found class name." All I do is copy and paste the script from two comments abopve and switch the safari and google chrome locations

tell application "Safari"

set current_tab to active tab in the front window
set the_url to the URL of current_tab
tell application "Google Chrome" to open location the_url

# Uncomment the next line to close tab after opening in Safari
# tell current_tab to close

end tell

What am I doing wrong???

@zhanggang807
Copy link

Thanks for this, it is exactly what I have been looking for. I am surprised it was so hard for me to find until I happened upon this thread.
So I was able to make an Automator app with the three scripts posted here above but when I try and adapt it to a single safari tab sent to chrome I get a "syntax error: Expected end of line, etc. but found class name." All I do is copy and paste the script from two comments abopve and switch the safari and google chrome locations

tell application "Safari"

set current_tab to active tab in the front window
set the_url to the URL of current_tab
tell application "Google Chrome" to open location the_url

# Uncomment the next line to close tab after opening in Safari
# tell current_tab to close

end tell

What am I doing wrong???

I also met this problem

@Dudemullet
Copy link

@JCDC85 @zhanggang807 It might just be that Safari does not expose the same api as Chrome ? I don't really know how applescript works

@ldeck
Copy link

ldeck commented Dec 21, 2020

Here's a variant to only open the current tab in safari with an optional line to close the tab

tell application "Google Chrome"
	
	set current_tab to active tab in the front window
	set the_url to the URL of current_tab
	tell application "Safari" to open location the_url
	
	# Uncomment the next line to close tab after opening in Safari
	# tell current_tab to close
end tell

That's great @Dudemullet. Here's a slight improvement to activate safari.

tell application "Google Chrome"
	set current_tab to active tab in the front window
	set the_url to the URL of current_tab
end tell
	
tell application "Safari"
	open location the_url
	activate
end tell

@CorgFather
Copy link

Found this, then realized you can right-click the URL in Chrome and choose Services (see pic). There's Open option which by default (Ventura) opens in Safari. If it's not in your menu, you can enable it under Settings > Keyboard > Shortcuts > Services. Check the box for Open.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment