Ping Pong?

Hey,

So i have mac minis set up in our retail stores to act as a media center. From HQ i wrote an app that syncs the music on my comp with the mac minis. But now we’ve gone for streaming radio. The unfortunate part is that our stores lose internet connection randomly which loses the connection to the streaming radio.

I’m trying to figure out a way for the mac mini to detect the lost connection and refresh the page. I thought of running some script that pings HQ every ten seconds and then somehow detects when it times out and refreshes.

you guys seem pretty bright… any ideas? Thanks in advance

The simplest one I know is due to Kai Edwards. The statement below is true if the internet is up (and Apple is live), and false otherwise:


(count (get (("http://www.apple.com" as URL)'s host & {dotted decimal form:""})'s dotted decimal form)) > 0

If you want to ‘bomb-proof’ it a bit, or it:

(count (get (("http://www.apple.com" as URL)'s host & {dotted decimal form:""})'s dotted decimal form)) > 0 or (count (get (("http://www.google.com" as URL)'s host & {dotted decimal form:""})'s dotted decimal form)) > 0

To run that in the background:


on idle
	if (count (get (("http://www.google.com" as URL)'s host & {dotted decimal form:""})'s dotted decimal form)) > 0 or (count (get (("http://www.google.com" as URL)'s host & {dotted decimal form:""})'s dotted decimal form)) > 0 then
		return 60 -- these are seconds to the next run
	else
		-- do what you do when the internet is down
		return 30
	end if
end idle

Save that as a stay-open application and it will run every 60 or 30 seconds depending on conditions

How would you get that to loop?

Say if it comes up false, could you start the ping again?


if (count (get (("http://www.apple.com" as URL)'s host & {dotted decimal form:""})'s dotted decimal form)) > 0 then
	set PingTestResult to "Ping Test Passed"
else
	set PingTestResult to "Ping Test Failed"
end if

set PingTest to button returned of (display dialog PingTestResult buttons {"OK", "Retry"} default button "OK")

If PingTest = "Retry" then

In an ‘on idle’ script as I’ve shown it, it repeats every 60 seconds (irrespective of the condition) if true, and every 30 seconds if false.

Something like this (just a modification of your script)


repeat
	if (count (get (("http://www.apple.com" as URL)'s host & {dotted decimal form:""})'s dotted decimal form)) > 0 then
		set PingTestResult to "Ping Test Passed"
	else
		set PingTestResult to "Ping Test Failed"
	end if
	set PingTest to button returned of (display dialog PingTestResult buttons {"OK", "Retry"} default button "OK")
	if PingTest = "OK" then
		exit repeat
	else
		delay 10
	end if
end repeat

Wow… thanks guys. I’m going to try this is a few stores today. I’ll let you know how it works :slight_smile:

Man i love the apple community…