Skip to content

Instantly share code, notes, and snippets.

@rnelson
Created November 2, 2011 19:34
Show Gist options
  • Save rnelson/1334646 to your computer and use it in GitHub Desktop.
Save rnelson/1334646 to your computer and use it in GitHub Desktop.
Test for a working network connection
set testHost to "google.com"
set errorSubject to "Internet Died"
set errorRecipientName to "Your Name"
set errorRecipientAddress to "your@ddr.ess"
set audioFile to "Macintosh HD:Users:rnelson:Music:iTunes:iTunes Music:Bad Religion:The Process of Belief:04 Broken.mp3" -- Broken, just like my internet
repeat
-- Try to use the network
set command to "/usr/sbin/scutil -r " & testHost
set resultText to do shell script command
if (resultText as string = "Reachable" as string) then
-- Pause
tell me
delay 10
end tell
else
-- Open some apps
tell application "QuickTime Player" to activate
-- Get the current volume
set currentVolume to output volume of (get volume settings)
set scaledVolume to round (currentVolume / (100 / 7))
-- Set the volume to max
set volume 7
-- Play an MP3
tell application "QuickTime Player"
open file audioFile
delay 2
play document 1
delay 240
end tell
-- Send an alert
tell application "Mail" to activate
delay 5
set dateString to (current date) as string
set body to "Unable to access " & testHost & " at " & dateString & ". Looks like the router is fine."
tell application "Mail"
set newEmail to make new outgoing message with properties {visible:true, subject:errorSubject, content:body}
tell newEmail
make new recipient at end of to recipients with properties {name:errorRecipientName, address:errorRecipientAddress}
end tell
send newEmail
end tell
-- Hide Mail
tell application "System Events"
set visible of process "Mail" to false
end tell
-- Restore the user's previous volume level
set volume output volume scaledVolume
-- Quit
exit repeat
end if
end repeat
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment