Im trying to get a script to ping an address thats contained within a text file.
The address are in the format of “12345.local”
Once the script has pinged one address i want it to display a “Passed” or “Failed” message.
Heres my scirpt so far,
set PingAddress to paragraphs of (read alias ((path to desktop folder as text) & "PingList.txt"))
repeat 3 times
if (count (get ({PingAddress}'s host & {dotted decimal form:""})'s dotted decimal form)) > 0 then
set PingTestResult to "Passed"
else
set PingTestResult to "Failed"
end if
set PingTest to button returned of (display dialog PingTestResult buttons {"OK"} default button "OK" with icon caution)
if PingTest = "OK" then
exit repeat
else
delay 3
end if
end repeat
I took the ping script from another post and tried modding it but with no luck, any ideas or help would be great!
‘PingAddress’ in your script is a list. So you need to loop through the items in the list.
I have modified and simplified your script to just show passed or failed. Instead of your ‘if/else’ statement I have used a ‘try/error’:
set PingAddressList to paragraphs of (read alias ((path to desktop folder as text) & "PingList.txt"))
repeat with PingAddress in PingAddressList
try
dotted decimal form of host of (("http://" & PingAddress) as URL)
set PingTestResult to "Passed"
on error
set PingTestResult to "Failed"
end try
display dialog PingAddress & return & PingTestResult buttons {"OK"} default button "OK" with icon caution
end repeat
One small thing ive just noticed,
Ive just tried it on al the mac’s on my network at work now 30+
And i cant realy sit there and press OK 30 times,
Is there a way of displaying the dialog for a selected time frame without any buttons then closing it?
I can’t seem to get a dialog to display with no buttons, but it’s relatively easy to add a timeout. At the end of the display dialog command add “giving up after x”, as in:
display dialog PingAddress & return & PingTestResult buttons {"OK"} default button "OK" with icon caution giving up after 5
Where 5 is the number of seconds you wish the dialog displayed for.