Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

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?

share|improve this question
    
Do you have to return the number of the current window? Or can you just get the window? –  anon173 Apr 20 '12 at 22:27
    
@ruddfawcett I need to be able to close the tab when I'm done and make sure that the script closes that tab, not some other tab. –  daviesgeek Apr 20 '12 at 22:30
    
Hmmm... Okay, so you want to assign a number to the current active window of Chrome, and then open a new tab in that window. You then want to close that tab? Am I understanding your question correctly? –  anon173 Apr 20 '12 at 22:31
    
@ruddfawcett The full script will open a tab in the current active window of Chrome, load a webpage, then close the page. It will then repeat that with about 25 URLs. –  daviesgeek Apr 20 '12 at 22:33

1 Answer 1

up vote 3 down vote accepted

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
share|improve this answer
    
Awesome! That'd be it! Thanks so much!!!! –  daviesgeek Apr 20 '12 at 22:54
    
No problem! I hope that it works for you! –  anon173 Apr 20 '12 at 22:55
    
Works like a charm! –  daviesgeek Apr 20 '12 at 22:59

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.