UNPKG

2.69 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
12property theProgram: "Google Chrome"
13
14on run argv
15 set theURL to item 1 of argv
16
17 -- Allow requested program to be optional,
18 -- default to Google Chrome
19 if (count of argv) > 1 then
20 set theProgram to item 2 of argv
21 end if
22
23 using terms from application "Google Chrome"
24 tell application theProgram
25
26 if (count every window) = 0 then
27 make new window
28 end if
29
30 -- 1: Looking for tab running debugger
31 -- then, Reload debugging tab if found
32 -- then return
33 set found to my lookupTabWithUrl(theURL)
34 if found then
35 set targetWindow's active tab index to targetTabIndex
36 tell targetTab to reload
37 tell targetWindow to activate
38 set index of targetWindow to 1
39 return
40 end if
41
42 -- 2: Looking for Empty tab
43 -- In case debugging tab was not found
44 -- We try to find an empty tab instead
45 set found to my lookupTabWithUrl("chrome://newtab/")
46 if found then
47 set targetWindow's active tab index to targetTabIndex
48 set URL of targetTab to theURL
49 tell targetWindow to activate
50 return
51 end if
52
53 -- 3: Create new tab
54 -- both debugging and empty tab were not found
55 -- make a new tab with url
56 tell window 1
57 activate
58 make new tab with properties {URL:theURL}
59 end tell
60 end tell
61 end using terms from
62end run
63
64-- Function:
65-- Lookup tab with given url
66-- if found, store tab, index, and window in properties
67-- (properties were declared on top of file)
68on lookupTabWithUrl(lookupUrl)
69 using terms from application "Google Chrome"
70 tell application theProgram
71 -- Find a tab with the given url
72 set found to false
73 set theTabIndex to -1
74 repeat with theWindow in every window
75 set theTabIndex to 0
76 repeat with theTab in every tab of theWindow
77 set theTabIndex to theTabIndex + 1
78 if (theTab's URL as string) contains lookupUrl then
79 -- assign tab, tab index, and window to properties
80 set targetTab to theTab
81 set targetTabIndex to theTabIndex
82 set targetWindow to theWindow
83 set found to true
84 exit repeat
85 end if
86 end repeat
87
88 if found then
89 exit repeat
90 end if
91 end repeat
92 end tell
93 end using terms from
94 return found
95end lookupTabWithUrl