解决macbook air m1合盖就睡眠断vpn的问题
2023-12-25 18:50:0 Author: blog.upx8.com(查看原文) 阅读量:7 收藏

今天遇到一台 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

重启系统 dns 服务


# redns

sudo killall -HUP mDNSResponder


文章来源: https://blog.upx8.com/3975
如有侵权请联系:admin#unsafe.sh