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