This is pretty straightforward, even though your logic path is a little convoluted 🙂
set networkUp to true -- assume the best
try
do shell script "ping -c 1 -t 2 www.google.com"
do shell script "ping -c 1 -t 2 www1"
on error -- network is down
set networkUp to false
display dialog "Oops. Network is down"
end try
if networkUp then
try
do shell script "ping -c 1 -t 2 www.apple.com"
open location "http://www.apple.com/"
on error -- network is down
display dialog "Oops. Site is down"
end try
end if
The idea here is to use AppleScript's
try block to catch errors - if the ping succeeds then the script progresses normally, but if it fails then it triggers the 'on error' clause.
So in this case I start off by pinging the two sites (google and www1). If either of these fail I post a 'Network down' message and set a flag indicating that the network is down.
Then, if the network is up (i.e. the error clause didn't trigger) then I use another try block to ping the second web site (in this case www.apple.com). If that ping fails it triggers the second 'on error' clause, otherwise it proceeds to open the URL.
Note that I'm just using 'open location' to open the URL. That won't necessarily fire Safari, depending on your browser preferences (it will use your default browser, so if that's Firefox, Chrome, etc. then that's what will open the URL). If you want a specific browser to open the URL that's easy, too, just a little more code.