Created
March 3, 2015 18:53
-
-
Save depressiveRobot/5c1eaf3f80c4d97660ab to your computer and use it in GitHub Desktop.
Open URL in Google Chrome. Switches to tab if already open or creates a new one.
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
# source: http://superuser.com/a/692131/424541 | |
on is_running(appName) | |
tell application "System Events" to (name of processes) contains appName | |
end is_running | |
set chromeRunning to is_running("Google Chrome") | |
if chromeRunning then | |
tell application "Google Chrome" | |
set i to 0 | |
set j to 0 | |
repeat with w in (windows) | |
set j to j + 1 | |
repeat with t in (tabs of w) | |
set i to i + 1 | |
if title of t contains "Gmail" then | |
set (active tab index of window j) to i | |
return | |
end if | |
end repeat | |
end repeat | |
tell application "Google Chrome" | |
activate | |
open location "http://mail.google.com/" | |
end tell | |
end tell | |
else | |
tell application "Google Chrome" | |
activate | |
open location "http://mail.google.com/" | |
end tell | |
end if |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
There's a minor bug here: you need to reset i to zero again for every window, not just at the beginning.