UNPKG

2.04 kBPlain TextView Raw
1property targetTab: null
2property targetTabIndex: -1
3property targetWindow: null
4
5on run argv
6 set theURL to item 1 of argv
7
8 tell application "Chrome"
9
10 if (count every window) = 0 then
11 make new window
12 end if
13
14 -- 1: Looking for tab running debugger
15 -- then, Reload debugging tab if found
16 -- then return
17 set found to my lookupTabWithUrl(theURL)
18 if found then
19 set targetWindow's active tab index to targetTabIndex
20 tell targetTab to reload
21 tell targetWindow to activate
22 set index of targetWindow to 1
23 return
24 end if
25
26 -- 2: Looking for Empty tab
27 -- In case debugging tab was not found
28 -- We try to find an empty tab instead
29 set found to my lookupTabWithUrl("chrome://newtab/")
30 if found then
31 set targetWindow's active tab index to targetTabIndex
32 set URL of targetTab to theURL
33 tell targetWindow to activate
34 return
35 end if
36
37 -- 3: Create new tab
38 -- both debugging and empty tab were not found
39 -- make a new tab with url
40 tell window 1
41 activate
42 make new tab with properties {URL:theURL}
43 end tell
44 end tell
45end run
46
47-- Function:
48-- Lookup tab with given url
49-- if found, store tab, index, and window in properties
50-- (properties were declared on top of file)
51on lookupTabWithUrl(lookupUrl)
52 tell application "Chrome"
53 -- Find a tab with the given url
54 set found to false
55 set theTabIndex to -1
56 repeat with theWindow in every window
57 set theTabIndex to 0
58 repeat with theTab in every tab of theWindow
59 set theTabIndex to theTabIndex + 1
60 if (theTab's URL as string) contains lookupUrl then
61 -- assign tab, tab index, and window to properties
62 set targetTab to theTab
63 set targetTabIndex to theTabIndex
64 set targetWindow to theWindow
65 set found to true
66 exit repeat
67 end if
68 end repeat
69
70 if found then
71 exit repeat
72 end if
73 end repeat
74 end tell
75 return found
76end lookupTabWithUrl