Created
June 1, 2016 22:43
-
-
Save stevenschobert/ba6845feb5b0db7cdf04d04362720424 to your computer and use it in GitHub Desktop.
AppleScript to find existing tab with URL, or open a new one.
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
tell application "Safari" | |
set topWindows to every window whose name is not "" | |
set numWindows to the number of topWindows | |
set didFind to false | |
set targetUrl to "http://localhost:3000/" | |
repeat with x from 1 to numWindows | |
set numTabs to the number of tabs in window x | |
repeat with y from 1 to numTabs | |
set tabUrl to the URL of tab y of window x | |
if tabUrl contains targetUrl then | |
set didFind to true | |
tell window x to set current tab to tab y | |
end if | |
end repeat | |
end repeat | |
if didFind is false then | |
tell window 1 to set current tab to (make new tab with properties {URL:targetUrl}) | |
end if | |
end tell |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment