Advertisement
Guest User

Controlling Geektool using Applescript

a guest
Jul 28th, 2010
1,231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Define and initialize a global variable used to store the IP
  2. # address between iterations of the Idle Loop
  3. global theStoredIPAddress
  4. set theStoredIPAddress to "" as string
  5.  
  6. # Begin the idle loop
  7. on idle
  8.    
  9.     # Runs a shell script that checks the IP address of en0 (Ethernet Adapter)
  10.     # If en0 returns no IP, checks en1 (AirPort Adapter)
  11.     # Stores the IP address to a variable as a string.
  12.     set theIPAddress to (do shell script "/sbin/ifconfig en0 | grep 'inet ' | awk '{print $2}'") as string
  13.     if theIPAddress = "" then
  14.         set theIPAddress to (do shell script "/sbin/ifconfig en1 | grep 'inet ' | awk '{print $2}'") as string
  15.     end if
  16.    
  17.    
  18.     # display dialog "IP Address: " & theIPAddress & return & "Stored Address: " & theStoredIPAddress with title "IP Address" --Line used to display current & stored IPs. For debugging.
  19.    
  20.    
  21.     # Compares current IP address to IP stored in gobal variable.
  22.     if theStoredIPAddress is not equal to theIPAddress then
  23.        
  24.         # Gets response of Ping shell script. "; exit 0" forces the script to
  25.         # return 0. Otherwise AppleScript bitches.
  26.         set thePingResponse to ""
  27.         set thePingResponse to (do shell script "ping -c 1 HOST.DOMAIN.COM 2>/tmp/errorfail.txt | grep \"64 bytes from\"; exit 0")
  28.        
  29.        
  30.         # display dialog thePingResponse with title "Ping Response" -- another debug line.
  31.        
  32.         # Sets the gloabl vaiable to the current IP for future iterations.
  33.         set theStoredIPAddress to theIPAddress
  34.        
  35.         # If the response variable (thePingResponse) is NOT empty (ping succeded)
  36.         # set the GeekTool group to visible. Else, make the group invisible
  37.         if thePingResponse is not equal to "" then
  38.             tell application "GeekTool"
  39.                 set visible of group "RO Pings" to true
  40.             end tell
  41.         else
  42.             tell application "GeekTool"
  43.                 set visible of group "RO Pings" to false
  44.             end tell
  45.         end if
  46.     end if
  47.    
  48.     # Wait 20 seconds before starting the idle loop again. 
  49.     return 5
  50.    
  51. end idle
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement