Reputation: 1
noob here trying to teach myself applescript and generally not very smart so apologies :|
i was looking at this question and the answers
Check for active internet connection with Applescript/Automator
and i wanted to make a applescript that runs constantly in the background and that puts a red dot in the menubar when i don't have an internet connection and a green one when i don't (using the AnyBar application) but i can't get it to work properly.
can someone please tell me what i am doing wrong. thank you so much!
repeat
repeat with i from 1 to 2
try
do shell script "ping -o -t 2 www.google.com"
exit repeat
tell application "AnyBar" to set image name to "green"
on error
tell application "AnyBar" to set image name to "orange"
delay 2
if i = 2 then tell application "AnyBar" to set image name to "red"
end try
end repeat
delay 60
end repeat
Upvotes: 0
Views: 469
Reputation: 285064
I'd recommend to use an applet (script saved as application) with an idle
handler rather than an infinite repeat loop
property imageName : "red"
property delayValue : 60
property googleURL : "http://www.google.com"
on run
set imageName to "red"
end run
on idle
if (count (get ((googleURL as URL)'s host & {dotted decimal form:""})'s dotted decimal form)) > 0 then
set imageName to "green"
else
if imageName is "green" then
set imageName to "orange"
set delayValue to 2
else if imageName is "orange" then
set imageName to "red"
set delayValue to 60
end if
end if
tell application "AnyBar" to set image name to imageName
return delayValue
end idle
Upvotes: 1