Skip to content

Instantly share code, notes, and snippets.

@voldmar
Created August 23, 2012 13:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save voldmar/3436919 to your computer and use it in GitHub Desktop.
Save voldmar/3436919 to your computer and use it in GitHub Desktop.
Script for reloading first Google Chrome tab with given prefix
#!/usr/bin/osascript
on run argv
set theUrl to "http://localhost:8000/api/"
if (count of argv) > 0 then
set theUrl to item 1 of argv
if not (theUrl starts with "http://" or theUrl starts with "https://") then
set theUrl to "http://" & theUrl
end if
end if
tell application "Google Chrome"
set found to false
set theWindowIndex to 0
repeat with theWindow in every window
set theTabIndex to 0
repeat with theTab in every tab of theWindow
set theTabIndex to theTabIndex + 1
if theTab's URL starts with theUrl then
set found to true
tell application "Google Chrome" to set active tab index of theWindow to theTabIndex
tell theTab to reload
tell theWindow to activate
end if
end repeat
end repeat
if not found then
set URL of (active tab of (make new window)) to theUrl
end if
end tell
end run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment