Internet Connection Checker

Hello all,

I’m looking to run a script that checks for my airport connection status every 10 seconds and is CPU FRIENDLY.

I’ve installed the XNetwork 2.0 scripting addtions, which are working nicely.

My current rendering is as follows:

repeat
	try
		set ping_result to (do shell script "ping -c 1 google.com")
	on error number errNum
		if (errNum = 2) then
			stop airport
			start airport
		end if
	end try
	do shell script {"sleep 10"}
end repeat

This seems to bog my Powerbook G4 down a bit and I’m in hopes that you can help.

Also, I’ve read where if a ping fails, applescript doesn’t stop the ping. Rather, it just stops paying attention to the effort to ping. I’d like to make sure I don’t leave any functions operating in limbo.

How do I do all of this?

Welcome. :slight_smile:

Try saving this as a “Stay Open” application and see if that makes any difference.

on idle
	try
		set ping_result to (do shell script "/sbin/ping -c 1 google.com")
	on error number errNum
		if (errNum = 2) then
			stop airport
			start airport
		end if
	end try
	return 10 -- seconds until next idle
end idle

Thanks!

This feels a little better so far.

What does idle refer to?