-
-
Save robjwells/3958402 to your computer and use it in GitHub Desktop.
Open current Safari URL in Chrome
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Open current Safari URL in Chrome | |
-- | |
-- Forked from https://gist.github.com/3153606 | |
-- which was forked in turn from https://gist.github.com/3151932 | |
tell application "System Events" | |
-- Check if Chrome is running | |
set chromeRunning to ((name of processes) contains "Google Chrome") | |
end tell | |
tell application "Safari" | |
-- Get the current Safari URL | |
set theURL to the URL of the current tab of window 1 | |
end tell | |
if chromeRunning is true then | |
-- Bundle id used to try to avoid a bug with Parallels & Chrome for Windows | |
tell application id "com.google.Chrome" | |
if (count of (every window where visible is true)) is 0 then | |
-- Make a new window if there are no visible ones | |
make new window | |
end if | |
end tell | |
else | |
launch application id "com.google.Chrome" | |
end if | |
tell application id "com.google.Chrome" | |
-- Check if the current tab is empty | |
if the URL of the active tab of window 1 is "chrome://newtab/" then | |
-- If it is, open theURL in it | |
set the URL of the active tab of window 1 to theURL | |
else | |
-- Otherwise make a new tab and open theURL | |
tell window 1 to make new tab with properties {URL:theURL} | |
end if | |
activate | |
end tell |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
All the hard work for this done by @prenagha. This fork has two main differences:
The latter’s mostly a hunch, and I can’t test it so I don’t know if it works. (It’s a response to @donschaffner’s comments on the original gist.)
Generally the code looks a bit different, and that’s because I rewrote it line-by-line so I knew exactly what was going on, and also to match my own idiosyncrasies (like replacing the single-use handler with a simple
tell
block).Usage: I’d recommend activating it from LaunchBar or FastScripts. Personally, I have it saved to
~/Library/Scripts/Applications/Safari
and call it through FastScripts with Control-Option-Command-C (⌃⌥⌘C).PS. Most of the revisions since my first are minor fiddling with meta stuff, such as changing the file extension to force GitHub’s syntax highlighting.