Skip to content

Instantly share code, notes, and snippets.

@depressiveRobot
Created March 3, 2015 18:53
Show Gist options
  • Save depressiveRobot/5c1eaf3f80c4d97660ab to your computer and use it in GitHub Desktop.
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.
# 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
@preminger
Copy link

There's a minor bug here: you need to reset i to zero again for every window, not just at the beginning.

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