1 | property targetTab: null
|
2 | property targetTabIndex: -1
|
3 | property targetWindow: null
|
4 |
|
5 | on 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 |
|
15 |
|
16 |
|
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 |
|
27 |
|
28 |
|
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 |
|
38 |
|
39 |
|
40 | tell window 1
|
41 | activate
|
42 | make new tab with properties {URL:theURL}
|
43 | end tell
|
44 | end tell
|
45 | end run
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 | on lookupTabWithUrl(lookupUrl)
|
52 | tell application "Chrome"
|
53 |
|
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 |
|
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
|
76 | end lookupTabWithUrl
|