解决macbook air m1合盖就睡眠断vpn的问题

发布时间: 2023-12-25

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

  1. ǝɔ∀ǝdʎz∀ɹɔ ?
    2023-12-27 15:07:13

    这意思是, 强行合盖不睡眠? 那合盖不省电了呀?

    1. 黑海洋
      2023-12-27 17:16:30

      可以让它伪睡眠

请在下方留下您的评论.加入TG吹水群