UNPKG

2.36 kBPlain TextView Raw
1(*
2Copyright (c) 2015-present, Facebook, Inc.
3
4This source code is licensed under the MIT license found in the
5LICENSE file at
6https://github.com/facebookincubator/create-react-app/blob/master/LICENSE
7*)
8
9property targetTab: null
10property targetTabIndex: -1
11property targetWindow: null
12
13on run argv
14 set theURL to item 1 of argv
15
16 with timeout of 2 seconds
17 tell application "Chrome"
18
19 if (count every window) = 0 then
20 make new window
21 end if
22
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 timeout
55end run
56
57-- Function:
58-- Lookup tab with given url
59-- if found, store tab, index, and window in properties
60-- (properties were declared on top of file)
61on lookupTabWithUrl(lookupUrl)
62 tell application "Chrome"
63 -- Find a tab with the given url
64 set found to false
65 set theTabIndex to -1
66 repeat with theWindow in every window
67 set theTabIndex to 0
68 repeat with theTab in every tab of theWindow
69 set theTabIndex to theTabIndex + 1
70 if (theTab's URL as string) contains lookupUrl then
71 -- assign tab, tab index, and window to properties
72 set targetTab to theTab
73 set targetTabIndex to theTabIndex
74 set targetWindow to theWindow
75 set found to true
76 exit repeat
77 end if
78 end repeat
79
80 if found then
81 exit repeat
82 end if
83 end repeat
84 end tell
85 return found
86end lookupTabWithUrl