image
image

Go Back   macosx.com > Design, Media, Programming & Scripting > Software Programming & Web Scripting

Reply
 
Thread Tools
  #1  
Old December 23rd, 2003, 09:44 AM
voice-'s Avatar
Registered User
 
Join Date: Oct 2001
Location: Narvik, Norway
Posts: 1,793
Thanks: 0
Thanked 0 Times in 0 Posts
voice- is on a distinguished road
How to close the Terminal window after a while using AppleScript?

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
Reply With Quote
  #2  
Old December 23rd, 2003, 11:21 AM
ElDiabloConCaca's Avatar
U.S.D.A. Prime
 
Join Date: Aug 2001
Location: San Antonio, Texas
Posts: 9,926
Thanks: 2
Thanked 63 Times in 59 Posts
ElDiabloConCaca has a spectacular aura aboutElDiabloConCaca has a spectacular aura aboutElDiabloConCaca has a spectacular aura about
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!
__________________
Power Macintosh G4/500MHz "Yikes!" 10.4.11 Server • 1024MB • 3 x 120GB + 320GB • DVR-111D • 2 x Radeon 7000 PCI • 2 x 17" CRT
MacBook 2.0GHz Core 2 Duo - White 10.5.5 • 2048MB • 80GB • CD-RW/DVD-ROM
iPod Photo 60GB • iPod nano 1GB • AT&T DSL 6Mb/768k
http://www.jeffhoppe.com
Reply With Quote
  #3  
Old December 23rd, 2003, 11:40 AM
voice-'s Avatar
Registered User
 
Join Date: Oct 2001
Location: Narvik, Norway
Posts: 1,793
Thanks: 0
Thanked 0 Times in 0 Posts
voice- is on a distinguished road
Just what I was looking for, thank you.
Reply With Quote
  #4  
Old December 23rd, 2003, 01:37 PM
ElDiabloConCaca's Avatar
U.S.D.A. Prime
 
Join Date: Aug 2001
Location: San Antonio, Texas
Posts: 9,926
Thanks: 2
Thanked 63 Times in 59 Posts
ElDiabloConCaca has a spectacular aura aboutElDiabloConCaca has a spectacular aura aboutElDiabloConCaca has a spectacular aura about
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.
__________________
Power Macintosh G4/500MHz "Yikes!" 10.4.11 Server • 1024MB • 3 x 120GB + 320GB • DVR-111D • 2 x Radeon 7000 PCI • 2 x 17" CRT
MacBook 2.0GHz Core 2 Duo - White 10.5.5 • 2048MB • 80GB • CD-RW/DVD-ROM
iPod Photo 60GB • iPod nano 1GB • AT&T DSL 6Mb/768k
http://www.jeffhoppe.com
Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off
Forum Jump


All times are GMT -5. The time now is 01:18 AM.


Mac Support® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0
Copyright 2000-2008 DigitalCrowd, Inc.