Skip to content

Instantly share code, notes, and snippets.

@studentIvan
Created June 21, 2021 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 studentIvan/a3e47c8980b3de435fd5de7cb74e9f70 to your computer and use it in GitHub Desktop.
Save studentIvan/a3e47c8980b3de435fd5de7cb74e9f70 to your computer and use it in GitHub Desktop.
Helpful developer's bash applescript (osascript) to open the tab with the specific url inside the google chrome new or reloaded. It may check the app running on the same port also and re-use this tab.
-- using example:
-- sleep 10 && osascript start.applescript "http://local.${PROJECT_DOMAIN}.com:8080" 8080 &
-- yarn start
on run argv
tell application "Google Chrome"
activate
set targetURL to (item 1 of argv)
-- I know I can parse it but I'm too lazy...
set targetPort to (item 2 of argv)
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 = targetURL or theTab's URL = targetURL & "/" or theTab's URL contains ":" & targetPort then
set found to true
exit
end if
end repeat
if found then
exit repeat
end if
end repeat
if found then
set theWindow's active tab index to theTabIndex
set URL of tab theTabIndex of theWindow to targetURL
set index of theWindow to 1
else
tell window 1 to make new tab with properties {URL:targetURL}
end if
end tell
tell application "System Events"
key down {command}
key down {option}
keystroke "i"
key up {option}
key up {command}
end tell
end run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment