Created
March 15, 2018 17:02
-
-
Save itissid/e167e079fddc07a5b528b6bf8dbea784 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
on run argv | |
set targetTabName to quoted form of (item 1 of argv) | |
set targetFullPath to (item 2 of argv) | |
tell application "Safari" | |
--Variables | |
set targetWindow to 0 | |
set targetTab to 0 | |
set found to false | |
--Repeat for Every Window | |
repeat with theWindow in every window | |
set targetWindow to theWindow | |
set theTabIndex to 0 | |
--Repeat for Every Tab in Current Window | |
repeat with theTab in every tab of theWindow | |
set theTabIndex to theTabIndex + 1 | |
set targetTab to theTab | |
--Get Tab Name & URL | |
set tabName to name of theTab | |
set tabURL to URL of theTab | |
--log tabName | |
--log tabURL | |
--log theTabIndex | |
if ((quoted form of (contents of tabName) as string) is equal to targetTabName) then | |
set found to true | |
--log "***Found the tab with URL:" & tabURL & " tab number " & theTabIndex | |
exit repeat | |
end if | |
end repeat | |
if found then | |
exit repeat | |
end if | |
end repeat | |
if found then | |
-- REFRESH THE TAB | |
activate window with targetWindow | |
tell theTab | |
set docUrl to URL of theTab | |
set URL of theTab to docUrl | |
set current tab of targetWindow to targetTab | |
end tell | |
else | |
--log "Did not find an open tab named: " & targetTabName & ". Opening it" | |
open location targetFullPath | |
activate | |
end if | |
end tell | |
end run | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment