How to return the number of the current window in Chrome and open a new tab in it

applescriptgoogle-chrometabs

I am writing an AppleScript in which I need to get the number of the current window of Google Chrome and open a new tab in it. I want something like this (pseudo code):

set curWindNum to the current window of Google Chrome // returns something like "window 4" or just "4"
open a new tab in window curWindNum

How do I do this?

Best Answer

Here is the beginning of a very simple AppleScript that will open a new tab at the end of the current window, and then it will load a URL. The script will wait 5 seconds (to allow the page to load) and then it will close that tab. I am still working on it, but this should do it for you. Let me know if you need some more help, or if you would like me to change something. Here is the script:

tell application "Google Chrome"
set ActivePage to window 1
set Tab1 to make new tab at end of tabs of ActivePage
set URL of Tab1 to "http://google.com"
delay 5
close active tab of window 1
end tell