Skip to content

Instantly share code, notes, and snippets.

@hbouhadji
Created April 27, 2022 16:19
Show Gist options
  • Save hbouhadji/5d1170e63207cc1b821c7d9245a43f90 to your computer and use it in GitHub Desktop.
Save hbouhadji/5d1170e63207cc1b821c7d9245a43f90 to your computer and use it in GitHub Desktop.
#!/bin/bash
osascript << EOF
set windowFounded to 0
set tabFounded to 0
tell application "$1"
set window_list to every window
set counter_window to 0
repeat with the_window in window_list
set counter_window to counter_window + 1
set tab_list to every tab in the_window
set counter to 0
repeat with the_tab in tab_list
set counter to counter + 1
set the_url to the URL of the_tab
if (the_url contains "$2") then
set windowFounded to counter_window
set tabFounded to counter
exit repeat
end if
end repeat
if (tabFounded is not 0 and windowFounded is not 0) then
exit repeat
end if
end repeat
if (tabFounded is not 0 and windowFounded is not 0) then
set active tab index of the_window to tabFounded
tell application "System Events" to tell process "$1"
perform action "AXRaise" of window windowFounded
end tell
else
open location "$2"
end if
end tell
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment