Applescript确定互联网可达性(Applescript determine Internet reachability)

编程入门 行业动态 更新时间:2024-10-28 07:26:14
Applescript确定互联网可达性(Applescript determine Internet reachability)

我最近遇到了不稳定的互联网连接,我只想用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 idle

I'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 try

Script 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

更多推荐

本文发布于:2023-07-26 10:30:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1274327.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:可达性   互联网   Applescript   reachability   Internet

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!