Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Define and initialize a global variable used to store the IP
- # address between iterations of the Idle Loop
- global theStoredIPAddress
- set theStoredIPAddress to "" as string
- # Begin the idle loop
- on idle
- # Runs a shell script that checks the IP address of en0 (Ethernet Adapter)
- # If en0 returns no IP, checks en1 (AirPort Adapter)
- # Stores the IP address to a variable as a string.
- set theIPAddress to (do shell script "/sbin/ifconfig en0 | grep 'inet ' | awk '{print $2}'") as string
- if theIPAddress = "" then
- set theIPAddress to (do shell script "/sbin/ifconfig en1 | grep 'inet ' | awk '{print $2}'") as string
- end if
- # display dialog "IP Address: " & theIPAddress & return & "Stored Address: " & theStoredIPAddress with title "IP Address" --Line used to display current & stored IPs. For debugging.
- # Compares current IP address to IP stored in gobal variable.
- if theStoredIPAddress is not equal to theIPAddress then
- # Gets response of Ping shell script. "; exit 0" forces the script to
- # return 0. Otherwise AppleScript bitches.
- set thePingResponse to ""
- set thePingResponse to (do shell script "ping -c 1 HOST.DOMAIN.COM 2>/tmp/errorfail.txt | grep \"64 bytes from\"; exit 0")
- # display dialog thePingResponse with title "Ping Response" -- another debug line.
- # Sets the gloabl vaiable to the current IP for future iterations.
- set theStoredIPAddress to theIPAddress
- # If the response variable (thePingResponse) is NOT empty (ping succeded)
- # set the GeekTool group to visible. Else, make the group invisible
- if thePingResponse is not equal to "" then
- tell application "GeekTool"
- set visible of group "RO Pings" to true
- end tell
- else
- tell application "GeekTool"
- set visible of group "RO Pings" to false
- end tell
- end if
- end if
- # Wait 20 seconds before starting the idle loop again.
- return 5
- end idle
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement