Created
July 20, 2012 22:10
-
-
Save prenagha/3153606 to your computer and use it in GitHub Desktop.
Open 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 currently open URL in Safari in Chrome | |
-- forked from https://gist.github.com/3151932 | |
-- | |
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 |
Great snippet, thanks.
And now it's back to doing the same thing again where it preferentially opens the page in Chrome for Windows.
Thanks for this @prenagha. I’ve just forked it, mostly to check if the current Chrome tab is empty (and if so to open the URL there).
@donschaffner My fork uses Chrome’s bundle id for everything except checking if it’s running, so that might solve your problem with Parallels & Chrome for Windows. (Unfortunately I can’t test this myself.)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ha! Renaming every instance of "Google Chrome" to "Google Chrome.app" fixed it.