Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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