1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | property targetTab: null
|
10 | property targetTabIndex: -1
|
11 | property targetWindow: null
|
12 |
|
13 | on 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 |
|
24 |
|
25 |
|
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 |
|
36 |
|
37 |
|
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 |
|
47 |
|
48 |
|
49 | tell window 1
|
50 | activate
|
51 | make new tab with properties {URL:theURL}
|
52 | end tell
|
53 | end tell
|
54 | end timeout
|
55 | end run
|
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 | on lookupTabWithUrl(lookupUrl)
|
62 | tell application "Chrome"
|
63 |
|
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 |
|
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
|
86 | end lookupTabWithUrl
|