@@ -7,23 +7,70 @@ This source code is licensed under the BSD-style license found in the
77of patent rights can be found in the PATENTS file in the same directory.
88*)
99
10+ property targetTab : null
11+ property targetTabIndex : -1
12+ property targetWindow : null
13+
1014on run argv
1115 set theURL to item 1 of argv
1216
13- tell application " Chrome"
17+ tell application " Google Chrome"
1418
1519 if (count every window) = 0 then
1620 make new window
1721 end if
1822
19- -- Find a tab currently running the debugger
23+ -- 1: Looking for tab running debugger
24+ -- then, Reload debugging tab if found
25+ -- then return
26+ set found to my lookupTabWithUrl(theURL)
27+ if found then
28+ set targetWindow's active tab index to targetTabIndex
29+ tell targetTab to reload
30+ tell targetWindow to activate
31+ set index of targetWindow to 1
32+ return
33+ end if
34+
35+ -- 2: Looking for Empty tab
36+ -- In case debugging tab was not found
37+ -- We try to find an empty tab instead
38+ set found to my lookupTabWithUrl(" chrome://newtab/" )
39+ if found then
40+ set targetWindow's active tab index to targetTabIndex
41+ set URL of targetTab to theURL
42+ tell targetWindow to activate
43+ return
44+ end if
45+
46+ -- 3: Create new tab
47+ -- both debugging and empty tab were not found
48+ -- make a new tab with url
49+ tell window 1
50+ activate
51+ make new tab with properties {URL :theURL}
52+ end tell
53+ end tell
54+ end run
55+
56+ -- Function:
57+ -- Lookup tab with given url
58+ -- if found, store tab, index, and window in properties
59+ -- (properties were declared on top of file)
60+ on lookupTabWithUrl (lookupUrl )
61+ tell application " Google Chrome"
62+ -- Find a tab with the given url
2063 set found to false
2164 set theTabIndex to -1
2265 repeat with theWindow in every window
2366 set theTabIndex to 0
2467 repeat with theTab in every tab of theWindow
2568 set theTabIndex to theTabIndex + 1
26- if theTab's URL as string contains theURL then
69+ if (theTab's URL as string ) contains lookupUrl then
70+ -- assign tab, tab index, and window to properties
71+ set targetTab to theTab
72+ set targetTabIndex to theTabIndex
73+ set targetWindow to theWindow
2774 set found to true
2875 exit repeat
2976 end if
@@ -33,17 +80,6 @@ on run argv
3380 exit repeat
3481 end if
3582 end repeat
36-
37- if found then
38- tell theTab to reload
39- set index of theWindow to 1
40- set theWindow's active tab index to theTabIndex
41- tell theWindow to activate
42- else
43- tell window 1
44- activate
45- make new tab with properties {URL :theURL}
46- end tell
47- end if
4883 end tell
49- end run
84+ return found
85+ end lookupTabWithUrl
0 commit comments