有没有什么办法可以让 Mac Mini 在未连接到互联网时发出声音警报?
我对 bash 很熟悉,所以如果 bash 是答案,我可以创建几个命令 - 一个用于打开它,一个用于关闭它 - 并为它创建一些桌面图标。
答案1
以下循环将向您的 ISP 发送一个 ICMP ECHO 请求 (ping),然后休眠一秒钟。如果两秒钟内未收到回复,它将播放文件 alarm.wav。
YOUR_ISP=1.2.3.4
while :
do
ping -t 2 -o -c 1 $YOUR_ISP || open alarm.wav
sleep 1
done
答案2
以下将会 ping 一次,如果 ping 失败则告诉 iTunes 开始播放。
ping -c 1 128.111.1.1 ||
osascript -e 'tell application "iTunes"' -e "play" -e "end tell"
答案3
只需这样做ping -A 1.1.1.1
,它就会在每次请求失败时发出警报。
小写a
表示每次请求成功后都会 ping 一次,而不是 ( ping -a 1.1.1.1
)
> man ping
...
-A Audible. Output a bell (ASCII 0x07) character when no packet is received before the next packet is
transmitted. To cater for round-trip times that are longer than the interval between
transmissions, further missing packets cause a bell only if the maximum number of unreceived
packets has increased.
-a Audible. Include a bell (ASCII 0x07) character in the output when any packet is received. This
option is ignored if other format options are present.