12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- property targetTab: null
- property targetTabIndex: -1
- property targetWindow: null
- property theProgram: "Google Chrome"
- on run argv
- set theURL to item 1 of argv
- set matchURL to item 2 of argv
-
-
- if (count of argv) > 2 then
- set theProgram to item 3 of argv
- end if
- using terms from application "Google Chrome"
- tell application theProgram
- if (count every window) = 0 then
- make new window
- end if
-
-
-
- set found to my lookupTabWithUrl(matchURL)
- if found then
- set targetWindow's active tab index to targetTabIndex
- tell targetTab to reload
- tell targetWindow to activate
- set index of targetWindow to 1
- return
- end if
-
-
-
- set found to my lookupTabWithUrl("chrome://newtab/")
- if found then
- set targetWindow's active tab index to targetTabIndex
- set URL of targetTab to theURL
- tell targetWindow to activate
- return
- end if
-
-
-
- tell window 1
- activate
- make new tab with properties {URL:theURL}
- end tell
- end tell
- end using terms from
- end run
- on lookupTabWithUrl(lookupUrl)
- using terms from application "Google Chrome"
- tell application theProgram
-
- set found to false
- set theTabIndex to -1
- repeat with theWindow in every window
- set theTabIndex to 0
- repeat with theTab in every tab of theWindow
- set theTabIndex to theTabIndex + 1
- if (theTab's URL as string) contains lookupUrl then
-
- set targetTab to theTab
- set targetTabIndex to theTabIndex
- set targetWindow to theWindow
- set found to true
- exit repeat
- end if
- end repeat
- if found then
- exit repeat
- end if
- end repeat
- end tell
- end using terms from
- return found
- end lookupTabWithUrl
|