检查用的AppleScript / Automator的有效的互联网连接 [英] Check for active internet connection with Applescript/Automator

查看:254
本文介绍了检查用的AppleScript / Automator的有效的互联网连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个工作流程的Automator来ping一台服务器,并下载我经常使用日程表的最新副本。这个时间表,然后复制到Dropbox的我,所以我可以在手机上查看。工作流下载最新的时间表之前,来自收件箱删除旧表。

I have an Automator workflow to ping a server, and download the latest copy of a schedule that I frequently use. This schedule then is copied to my dropbox so I can view it on my phone. Before the workflow downloads the newest schedule it deletes the old schedule from dropbox.

这工作得很好,除非我没有激活的Internet连接。当我没有一个有效的互联网连接,工作流仍然会打开下拉框,删除旧表,并尝试下载最新的一个。因为没有连接,它不会下载任何东西。然后,如果我的连接变得活跃空的Dropbox将同步和日程安排将我的手机中删除。

This works well, except when I don't have an active internet connection. When I don't have an active internet connection, the workflow will still open up dropbox, delete the old schedule, and try to download the newest one. Because there is no connection, it doesn't download anything. Then if my connection becomes active the empty dropbox will sync and the schedule will be deleted from my phone.

我想补充的AppleScript code几行来ping服务器,看看我有一个活动连接。如果我不这样做,然后再等待大约5秒钟和ping。我想有5 ping尝试,并在这一点上,如果我还没有一个有效的连接,然后我想完全退出。

I'm trying to add a few lines of applescript code to ping a server to see if i have an active connection. If I don't, then wait about 5 seconds and ping again. I want to have 5 ping attempts and at that point if i still do not have an active connection then I want to quit entirely.

我很新的AppleScript,所以我越来越挂了如何从一个命令处理错误,在这种情况下,平。如果命令平-o www.apple.com失败,等待5秒钟,然后重试平。如果5次失败的尝试然后退出完全。

I'm very new to applescript, so I'm getting hung up on how to handle an error from a command, in this case, the ping. If command "ping -o www.apple.com" fails, wait 5 seconds and retry the ping. If 5 failed attempts then quit entirely.

推荐答案

也许这样的事情?

repeat with i from 1 to 5
    try
        do shell script "ping -o www.apple.com"
        exit repeat
    on error
        delay 5
        beep
        if i = 5 then error number -128
    end try
end repeat
say "Connected"

这篇关于检查用的AppleScript / Automator的有效的互联网连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆