1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | property targetTab: null
|
9 | property targetTabIndex: -1
|
10 | property targetWindow: null
|
11 | property theProgram: "Google Chrome"
|
12 |
|
13 | on run argv
|
14 | set theURL to item 1 of argv
|
15 |
|
16 |
|
17 |
|
18 | if (count of argv) > 1 then
|
19 | set theProgram to item 2 of argv
|
20 | end if
|
21 |
|
22 | using terms from application "Google Chrome"
|
23 | tell application theProgram
|
24 |
|
25 | if (count every window) = 0 then
|
26 | make new window
|
27 | end if
|
28 |
|
29 |
|
30 |
|
31 |
|
32 | set found to my lookupTabWithUrl(theURL)
|
33 | if found then
|
34 | set targetWindow's active tab index to targetTabIndex
|
35 | tell targetTab to reload
|
36 | tell targetWindow to activate
|
37 | set index of targetWindow to 1
|
38 | return
|
39 | end if
|
40 |
|
41 |
|
42 |
|
43 |
|
44 | set found to my lookupTabWithUrl("chrome://newtab/")
|
45 | if found then
|
46 | set targetWindow's active tab index to targetTabIndex
|
47 | set URL of targetTab to theURL
|
48 | tell targetWindow to activate
|
49 | return
|
50 | end if
|
51 |
|
52 |
|
53 |
|
54 |
|
55 | tell window 1
|
56 | activate
|
57 | make new tab with properties {URL:theURL}
|
58 | end tell
|
59 | end tell
|
60 | end using terms from
|
61 | end run
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 | on lookupTabWithUrl(lookupUrl)
|
68 | using terms from application "Google Chrome"
|
69 | tell application theProgram
|
70 |
|
71 | set found to false
|
72 | set theTabIndex to -1
|
73 | repeat with theWindow in every window
|
74 | set theTabIndex to 0
|
75 | repeat with theTab in every tab of theWindow
|
76 | set theTabIndex to theTabIndex + 1
|
77 | if (theTab's URL as string) contains lookupUrl then
|
78 |
|
79 | set targetTab to theTab
|
80 | set targetTabIndex to theTabIndex
|
81 | set targetWindow to theWindow
|
82 | set found to true
|
83 | exit repeat
|
84 | end if
|
85 | end repeat
|
86 |
|
87 | if found then
|
88 | exit repeat
|
89 | end if
|
90 | end repeat
|
91 | end tell
|
92 | end using terms from
|
93 | return found
|
94 | end lookupTabWithUrl
|