0
我试图在主机进入或脱机时使此AppleScript提醒我。所有工作正常,如果我将do shell script
行更改为set connected to true
/false
,所以我知道其余的代码工作。但do shell script
行似乎总是返回true。当我在终端中运行它时,它工作正常,但由于某种原因,在AppleScript中它没有。即使我将主机设置为每次在终端中返回false的随机IP地址,每次都会返回“真”(do shell script
)。我从this得到了shell脚本的答案。AppleScript ping shell脚本始终返回true
on run
set oldconnected to false
repeat
set connected to do shell script "ping -o -t 5 My-Host.local >/dev/null && echo yes || echo no" as boolean
if connected and not oldconnected then
display notification "Device has connected"
end if
if not connected and oldconnected then
display notification "Device has disconnected"
end if
set oldconnected to connected
delay 5
end repeat
end run