分享 MacOS 的一些系统fix脚本(dns、sleep)

现在在用 macbook air m1,太离谱了,一合盖就睡眠断 vpn,然后还有极高概率 dns broken,完全无法自动恢复,经过一段时间摸索,找出来了可行处理手段

合盖不睡眠

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/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 服务

1
2
3
# redns

sudo killall -HUP mDNSResponder

分享 MacOS 的一些系统fix脚本(dns、sleep)
https://hunsh.net/archives/136/
发布于
2022年11月25日
许可协议