@@ -7,23 +7,70 @@ This source code is licensed under the BSD-style license found in the
7
7
of patent rights can be found in the PATENTS file in the same directory.
8
8
*)
9
9
10
+ property targetTab : null
11
+ property targetTabIndex : -1
12
+ property targetWindow : null
13
+
10
14
on run argv
11
15
set theURL to item 1 of argv
12
16
13
- tell application " Chrome"
17
+ tell application " Google Chrome"
14
18
15
19
if (count every window) = 0 then
16
20
make new window
17
21
end if
18
22
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
20
63
set found to false
21
64
set theTabIndex to -1
22
65
repeat with theWindow in every window
23
66
set theTabIndex to 0
24
67
repeat with theTab in every tab of theWindow
25
68
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
27
74
set found to true
28
75
exit repeat
29
76
end if
@@ -33,17 +80,6 @@ on run argv
33
80
exit repeat
34
81
end if
35
82
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
48
83
end tell
49
- end run
84
+ return found
85
+ end lookupTabWithUrl
0 commit comments