• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: connnected?!
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: connnected?!


  • Subject: Re: connnected?!
  • From: Steve Mills <email@hidden>
  • Date: Tue, 7 Oct 2003 15:06:55 -0500

On Tuesday, Oct 7, 2003, at 14:10 US/Central, Patrick Mast wrote:

but i am not very happy with the ping-solution. i got the impression that the ping command sometimes returns an error when i am online and sets an internal variable to offline. with the next next ping without error the scripts thinks i am online again, so the script will be excecuted again.

is there any reliable alternative to the ping-test? i am nearly sure there is...

I was just doing something like this today.

From my tests, do shell script won't return an error, even if ping times out. ping will return after 10 seconds regardless. What I did was add the quiet flag "-q", because I'm only interested in one line of the summary returned by ping:

1 packets transmitted, 1 packets received, 0% packet loss

If the packets received is 1, the server is returned the ping. If it's 0, it didn't. Here's a hunk of my script. The routines FindEndOfString and FindSpaceAfter do just what they say, so you should be able to roll your own:

set pingRes to (do shell script "ping -q -c 1 'www.apple.com'")
set startPos to my FindEndOfString("packets transmitted, ", pingRes)
set endPos to my FindSpaceAfter(startPos, pingRes)
set packetsReceived to (text startPos thru endPos of pingRes) as number

if packetsReceived > 0 then
--The server is awake and responding.
end if

Steve Mills
Drummer, Mac geek
http://sjmills5.home.mchsi.com/
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: connnected?!
      • From: Christopher Nebel <email@hidden>
References: 
 >connnected?! (From: Patrick Mast <email@hidden>)

  • Prev by Date: newbie question in Safari
  • Next by Date: Re: Option key (was Re: Sorting)
  • Previous by thread: connnected?!
  • Next by thread: Re: connnected?!
  • Index(es):
    • Date
    • Thread