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'm trying to launch 3 tabs and run a script in each with applescript. So far I havent been able to get this done. Currently I have:

tell application "Terminal"
    activate
    do script "ping google.com"
    tell application "System Events"
        keystroke "t" using {command down}
        do script "ping yahoo.com"
    end tell
    tell application "System Events"
        keystroke "t" using {command down}
        do script "ping msn.com"
    end tell
end tell

This will launch 3 tabs but the pings don't execute in the last two tabs?

I'm probably missing something easy here.

share|improve this question
add comment

1 Answer 1

up vote 2 down vote accepted
  1. "System Events" doesn't understand what you want to do with do script, use the do script command outside of the tell application "System Events" block.

  2. You must specify a window or tab when using the do script command, otherwise a new window will open.

Updated (Lion) :

tell application "Terminal"
  activate
  do script "ping google.com"
  my makeTab()
  do script "ping yahoo.com" in tab 2 of front window
  my makeTab()
  do script "ping msn.com" in tab 3 of front window
end tell

on makeTab()
  tell application "System Events" to keystroke "t" using {command down}
  delay 0.2
end makeTab
share|improve this answer
    
THANKS! This works perfect in OSX 10.6.8, but in Lion it will try and ping google in all 3 windows? Not sure whats going on there? –  Nick Jul 28 '12 at 17:00
    
Perhaps on Lion+, you must specify the tab and the window. I edited my answer. –  jackjr300 Jul 28 '12 at 17:31
add comment

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.