今天遇到一台 macbook air m1,太离谱了,一合盖就睡眠断 vpn,然后还有极高概率 dns broken,完全无法自动恢复,顺手就写了个可行处理脚本.
MacOS系统fix脚本(dns、sleep)
#!/bin/bash
#***************************************************************************
#*** noz - prevent laptop from sleeping when lid is closed
#***************************************************************************
#***** set some defaults *****
BATTERY_SLEEP=5 # in minutes
DEF_WAKE_LEN=36000 # in seconds
#***** determine timeout value *****
timeout_len=${1:-$DEF_WAKE_LEN}
function prevent_sleep() {
echo -n "Preventing sleep for $timeout_len seconds; press <enter> to continue..."
sudo pmset -b disablesleep 1
sudo pmset -b sleep 0
}
function enable_sleep() {
# $1: <enter> = 0, timeout = 1, Ctrl-C = undef
#----- insert a newline for timeout or Ctrl-C -----
if [[ ${1:-1} -eq 1 ]]; then echo; fi
echo "Restoring previous battery sleep setting: $BATTERY_SLEEP"
sudo pmset -b disablesleep 0
sudo pmset -b sleep $BATTERY_SLEEP
#----- sleep on timeout only -----
if [[ ${1:--1} -eq 1 ]]; then sudo pmset sleepnow; fi
exit
}
#***** prevent it from sleeping *****
prevent_sleep
#***** trap Ctrl-C *****
trap enable_sleep INT
#***** wait for an enter *****
read -t $timeout_len
rc=$?
#***** re-enable normal sleep *****
enable_sleep $rc
# redns
sudo killall -HUP mDNSResponder
这意思是, 强行合盖不睡眠? 那合盖不省电了呀?
可以让它伪睡眠