noob在这里试图自学苹果,而且一般不那么聪明,所以道歉:|
我正在看这个问题和答案
Check for active internet connection with Applescript/Automator
我想制作一个在后台不断运行的AppleScript,当我没有互联网连接时会在菜单栏中放一个红点,而当我没有互联网连接时使用绿点(使用AnyBar应用程序)但我不能让它正常工作。
有人可以告诉我我做错了什么。非常感谢!
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
答案 0 :(得分:1)
我建议使用applet(保存为应用程序的脚本)和idle
处理程序而不是无限重复循环
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