How to close the Terminal window after a while using AppleScript?

voice-

Registered
I'm writing a newbie AppleScript ping application, the intention is to check internet connection with only one click. So far, the code looks like this:

tell application "Terminal"
do script "ping -c 10 www.vg.no"
end tell​

As you've probably guessed, this opens Terminal and pings vg.no 10 times.
Now I want to add a little simplicity. I want it to bring Terminal to the front when I run the script, and I want it to close Terminal 10 seconds after the ping is successful/unsuccessful. This should allow plenty of time for me to see if I'm connected. Could anyone please tell me how to do this? I can quit the Terminal, but I can't make it wait first.

In summary, what I want is for the AppleScript to:
  • Open Terminal
  • Ping a webserver
  • Bring the Termianl to the front (or otherwise bring the result to the front)
  • Close whatever result it gets after 10 seconds
 

ElDiabloConCaca

U.S.D.A. Prime
An easy and simple Applescript would be:

Code:
tell application "Terminal"
	activate
	do script "ping -c 10 www.vg.no"
	delay 15
	quit
end tell
The "activate" command will bring the Terminal to the front. The "delay xx" will make the script wait xx seconds; in this case, 15, which is plenty of time for the ping to complete and kick the user back to the prompt, where the Terminal will quit without complaining that there are processes still running.

Hope that helps!
 

ElDiabloConCaca

U.S.D.A. Prime
Hehe... glad I could help, and I have to admit, that was my first try at AppleScript programming... ever!

I found a couple sites that really helped get that bit of code together with many tips and tricks... I can't remember off the top of my head, but if you'd like them, I'm sure I could find them again and post them here.
 
Top