hamw wrote:I have a computer on my home ethernet network that has been hanging up occasionally. I'd like to use an applescript in Indigo to monitor its status and then, if it does not respond, use an appliance link to restart it. The reset portion is easy, but I don't really know where to begin to get the computer's status and then use that info to trigger the action. Any ideas?
using terms from application "IndigoServer"
on dashboardUpdate()
local thePing, tempCSVholder, oldDelims
local LANIPList
--
-- assume indigo variables are defined D-LANIP and D-LAN. D_LANIP contains a list of IP's you want to ping comma separated.
--
set oldDelims to AppleScript's text item delimiters -- save their current state
set AppleScript's text item delimiters to {","} -- declare new delimiters
--
-- LAN access checking
set tempCSVholder to value of variable "D-LANIP"
set LANIPList to text items of tempCSVholder
set value of variable "D-LAN" to 1
repeat with i from 1 to (count of LANIPList)
try
set thePing to do shell script "ping -o -t 2 -c 2 " & item i of LANIPList & "|grep -e %"
if thePing contains "0 packets" then
set value of variable "D-LAN" to 0
end if
on error
set value of variable "D-LAN" to 0
end try
end repeat
set AppleScript's text item delimiters to oldDelims -- restore them
end dashboardUpdate
end using terms from
-- Set some variables.
set theIP to "192.168.1.101" -- The IP of the computer to check.
set theTimeout to 20 -- The time, in milliseconds, to wait before assuming the ping failed.
-- Check to see if the Mac Pro (staic IP) is on the network.
-- This shell script compound command pings theIP with a timeout of theTimeout milliseconds, then pipes it through grep to grab only the line containing the percent of packet loss. That's then piped through sed twice to remove the leading and trailing data around the packet loss percentage. The result returned from the compound command is number string (either 0.0 or 100, or nothing at all, indicating failure to ping as well).
set theResult to do shell script "/sbin/ping -qon -c 1 -W " & theTimeout & " " & theIP & " | /usr/bin/grep % | /usr/bin/sed \"s/.*,\\ //\" | /usr/bin/sed \"s/%.*//\""
if theResult is "" then
set theResult to 100 -- Set to 100 if no result was returned to allow numerical comparison below.
end if
-- If the result is greater than 0, then the 1 ping sent was not returned within the 20 milisecond timeout specified in the script above, thus the computer is likely not awake or not connected to the network. The "isMacProOnline" variable is assumed to already exist in Indigo.
if theResult as number > 0 then
tell application "IndigoServer"
set value of variable "isMacProOnline" to "false"
end tell
else
tell application "IndigoServer"
set value of variable "isMacProOnline" to "true"
end tell
end if
Users browsing this forum: No registered users and 4 guests