Skip to content

Instantly share code, notes, and snippets.

@wadetb
Forked from mayoff/gist:1138816
Last active December 28, 2015 03:19
Show Gist options
  • Save wadetb/7434425 to your computer and use it in GitHub Desktop.
Save wadetb/7434425 to your computer and use it in GitHub Desktop.
Updated to take the URL to refresh from the command line arguments.
-- Usage: osascript refresh.scpt https://www.google.com/
-- Be careful to give the final URL after canonicalization, redirects, etc.
on run arg
set theUrl to arg's first item
tell application "Google Chrome"
activate
if (count every window) = 0 then
make new window
end if
set found to false
set theTabIndex to -1
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 = theUrl as string) then
set found to true
exit repeat
end if
end repeat
if found then
exit repeat
end if
end repeat
if found then
tell theTab to reload
set theWindow's active tab index to theTabIndex
set index of theWindow to 1
else
tell window 1 to make new tab with properties {URL: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