After getting inspired by this Reddit thread, I finally started playing around with GeekTool. This is what I came up with. I’m pretty happy with the design and layout, but my router ping scripts bugged me when I was not at work. Fortunately GeekTool 3.0 supports AppleScript, so a solution wasn’t far off. Check out my demo, below.
The script is below. Since it uses an idle handler, you need to save it as an application with the “Stay open” option checked. I did my script testing and debugging before I put the handler in there, just to simplify things. I’ll leave comments open if anyone has any questions.
# 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 SERVER.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 succeeded)
# 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 20
end idle
Update: You can grab the Geeklets from here, if you’re so inclined.