Check for active internet connection with Applescript/Automator

萝らか妹 提交于 2019-12-05 09:38:14

Maybe something like this?

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"
David

The above script causes automator's applescript to hang if a domain is not available. It works fine in AppleScript Editor if you add -t X where X is a number of seconds ping should time out otherwise it'll hang indefinitely as well.

repeat with i from 1 to 2
    try
        do shell script "ping -o -t 2 www.googleasda.com"
        exit repeat
    on error
        say "Couldn't connect"
        delay 2
        say "Error after delay 5"
        beep
        if i = 2 then error number -128
    end try
end repeat
say "Connected"
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!