【发布时间】:2022-07-30 06:35:55
【问题描述】:
当我由于某种原因通过 FTP 上传大量文件时,我的 WiFi 连接停止工作。连接没有显示任何问题,为了解决这个问题,禁用并重新启用 wifi 就足够了。如何在脚本编辑器中使用 AppleScript 自动重启它?
【问题讨论】:
标签: macos networking automation applescript
当我由于某种原因通过 FTP 上传大量文件时,我的 WiFi 连接停止工作。连接没有显示任何问题,为了解决这个问题,禁用并重新启用 wifi 就足够了。如何在脚本编辑器中使用 AppleScript 自动重启它?
【问题讨论】:
标签: macos networking automation applescript
我的解决方案是这个脚本每秒钟检查一次与谷歌的连接,如果超时关闭并重新打开 en0 连接。
do shell script "echo 1" with administrator privileges # request password in advance with an excuse
repeat while true
try
do shell script "nc -w 3 -z www.google.com 80"
# do shell script "ping -c 1 google.com" # possible alternative
log "Internet works"
on error
log "Restarting internet..."
do shell script "sudo ifconfig en0 down" with administrator privileges
do shell script "sudo ifconfig en0 up" with administrator privileges
log "Done."
delay 5
end try
delay 1 # wait a second before the next internet checking
end repeat
【讨论】: