Use AppleScript to Query internet connection
I'm new to AppleScript and was looking to have a script that can alert me when my network status changes. I'm wanting this to help diagnose issues when I'm home and away and trying to be a little creative and need some assistance.
What I'm looking for is a script that will display a message on the screen when the network is down (for example unable to connect to apple.com) and will say The Network is Offline and will disappear once it's back online. But As the netowrk comes back online I also want it to shoot me a text notifying me of such an event and have my computer say the network is back online. I would like to have this run non stop in the background if possible so it will need to be repeating assuming this doesn't put any kind of strain on my imac.
My current code bits:
--sends a text to myself
tell application "Messages"
send “Network is back online" to buddy "XXXXXXXXXX" of service "E:myemail@apple.com"
end tell
repeat with i from 1 to 5
try
do shell script "ping -o www.apple.com"
exit repeat
on error
delay 5
beep
if i = 5 then error number -128
end try
end repeat
say "Network is back online"
This isn't much and I can't even get these two bits working together but figured someone else may have an interest in this as well and despite multiple searches I can't find anything exactly like this and I'm not to the point where I could take something similar and make it work for me yet.
as a side note I do have it set to sleep after an 3 hours and do have the wake function enabled and my computer does have a password lock. if that's an issue I'd appreciate help around that as well or I may use any scripts provided and just go from there.