我最近遇到了不稳定的互联网连接,我只想用applescript制作一个程序,它提醒我什么时候我的互联网可以到达,这样我就可以上网了。 例如,基本上,该程序通过ping google.com来检查互联网。 我知道我可以使用applescript运行shell脚本,但问题是,如何获取ping的返回值并将其放入if语句中?
I am recently experiencing unstable Internet connection I just want to make a program with applescript that reminds me when my Internet is reachable so I can go online. Basically the program checks the Internet by pinging google.com for example. I know I can run shell script using applescript, but the problem is, how to get the return value of the ping and put it in an if statement?
最满意答案
我已经添加了两个脚本。
第一次检查您的互联网连接一次 。
第二个每分钟在后台运行,并显示一个弹出窗口,如果它可以访问互联网。
脚本1
try set thePing to do shell script "/sbin/ping -o -c 5 8.8.8.8" on error set thePing to "no internet connection" end try脚本2
(* 1. Save as an Application: Script Editor > File > Export… > File Format: Application 2. Check "Stay open after run handler" 3. Run the app or add it to your login items: System Preferences > Users & Groups > User > Login Items > Press the "+" button # http://stackoverflow.com/questions/43250408/applescript-determine-internet-reachability *) on idle try set thePing to do shell script "/sbin/ping -o -c 5 8.8.8.8" if thePing does not contain "error" then display dialog "The internet connection is up" end if on error set thePing to "error: no internet connection" end try delay 60 end idleI've added two scripts.
The first one checks your internet connection once.
The second runs in the background every minute and displays a popup if it can reach the internet.
Script 1
try set thePing to do shell script "/sbin/ping -o -c 5 8.8.8.8" on error set thePing to "no internet connection" end tryScript 2
(* 1. Save as an Application: Script Editor > File > Export… > File Format: Application 2. Check "Stay open after run handler" 3. Run the app or add it to your login items: System Preferences > Users & Groups > User > Login Items > Press the "+" button # http://stackoverflow.com/questions/43250408/applescript-determine-internet-reachability *) on idle try set thePing to do shell script "/sbin/ping -o -c 5 8.8.8.8" if thePing does not contain "error" then display dialog "The internet connection is up" end if on error set thePing to "error: no internet connection" end try delay 60 end idle更多推荐
发布评论