Applescript
repeat
try
set ping_result to (do shell script "ping -t 2 -c 1 192.168.2.1")
--display dialog ping_result buttons "OK" default button 1 with icon 2
on error errStatement number errNum --errStatement holds text of error message, errNum the integer code described in either 'man ping' or sysexits.h
if (errNum = 2) then
tell application "GrowlHelperApp"
set the allNotificationsList to {"Network Check"}
set the enabledNotificationsList to {"Network Check"}
register as application "Network Check" all notifications allNotificationsList default notifications enabledNotificationsList icon of application "Network Check"
notify with name "Network Check" title "Network Check" description "Wireless is down. Will try to restart" application name "Network Check"
end tell
do shell script "scselect \"Ethernet only\">/dev/null && scselect 'Automatic'>/dev/null"
tell application "GrowlHelperApp"
set the allNotificationsList to {"Network Check"}
set the enabledNotificationsList to {"Network Check"}
register as application "Network Check" all notifications allNotificationsList default notifications enabledNotificationsList icon of application "Network Check"
notify with name "Network Check" title "Network Check" description "Restart complete. Internet should revive itself any moment." application name "Network Check"
end tell
delay 60
end if
end try
delay 2
end repeat
Shell script
#!/bin/sh
while sleep 1; do
if ping -n -o -c 1 -t 1 192.168.2.1>>/dev/null; then
sleep 1
else
echo restarting `date`
osascript -e 'tell application "GrowlHelperApp" ' \
-e ' set the allNotificationsList to {"Network Check"} ' \
-e ' set the enabledNotificationsList to {"Network Check"} ' \
-e ' register as application "Network Check" all notifications allNotificationsList default notifications enabledNotificationsList icon of application "Network Check" ' \
-e ' notify with name "Network Check" title "Network Check" description "Wireless is down. Will try to restart" application name "Network Check" ' \
-e 'end tell'
scselect "Ethernet only" && scselect "Automatic"
osascript -e 'tell application "GrowlHelperApp" ' \
-e ' set the allNotificationsList to {"Network Check"} ' \
-e ' set the enabledNotificationsList to {"Network Check"} ' \
-e ' register as application "Network Check" all notifications allNotificationsList default notifications enabledNotificationsList icon of application "Network Check" ' \
-e ' notify with name "Network Check" title "Network Check" description "Restart complete. Internet should revive itself any moment." application name "Network Check" ' \
-e 'end tell'
sleep 65
echo wakeup
fi
done
No comments:
Post a Comment