我有两台 Macbook Air(一台用于工作,一台用于个人),当我的 Macbook 处于关闭状态,并且本应处于睡眠状态时,它会自动连接到我的蓝牙耳机,而我却没有机会将它们连接到其他设备,这让我很抓狂。我该如何让我的电脑不是睡眠状态下自动连接蓝牙设备?我没有看到任何内置选项可以禁用此功能。
答案1
蓝调小憩似乎只需一个包就能解决问题。
答案2
MacOS 没有内置此选项,但可以很容易地将几个 Homebrew 软件包连接在一起以实现相同的功能。以下是我用来设置脚本的步骤,该脚本可在睡眠时禁用蓝牙并在唤醒时重新启用蓝牙(需要对终端有基本的了解):
- 安装 Homebrew:https://brew.sh/
brew install sleepwatcher
brew services start sleepwatcher
(MacOS 对话框将提示您授予权限。)brew install blueutil
- 运行
blueutil
以确认该实用程序具有所需的 MacOS 权限。 - 创建
~/.sleep
、~/.wakeup
和~/.sleepwatcher.log
内容,如下所示。 - 运行
which blueutil
并确认路径与下面脚本中使用的路径相匹配(或相应地更新脚本) chmod 700 ~/.sleep
chmod 700 ~/.wakeup
然后盖上盖子,等待几秒钟,再次打开并检查~/.sleepwatcher.log
。
文件内容~/.sleep
:
#!/bin/bash
# Sleepwatcher (Homebrew package) script that runs on sleep.
# See also: ~/.sleep, ~/.wakeup, ~/.sleepwatcher.log
/opt/homebrew/bin/blueutil --power off
echo "$(date -Iseconds) -- Sleep event detected, bluetooth disabled. Bluetooth status: $(/opt/homebrew/bin/blueutil --power)" >> ~/.sleepwatcher.log
文件内容~/.wakeup
:
#!/bin/bash
# Sleepwatcher (Homebrew package) script that runs on wakeup.
# See also: ~/.sleep, ~/.wakeup, ~/.sleepwatcher.log
/opt/homebrew/bin/blueutil --power on
echo "$(date -Iseconds) -- Wake event detected, bluetooth enabled. Bluetooth status: $(/opt/homebrew/bin/blueutil --power)" >> ~/.sleepwatcher.log
文件内容~/.sleepwatcher.log
:
# Sleepwatcher activity log. See also ~/.wakeup and ~/.sleep scripts.
编辑:另外在睡觉时禁用 wifi 访问
上述功能还可以轻松扩展,以禁用睡眠时连接 wifi 网络的功能。
~/.sleep
:
/opt/homebrew/bin/blueutil --power off
/usr/sbin/networksetup -setairportpower en0 off
echo "$(date -Iseconds) -- Sleep event detected. Disabled bluetooth and wifi. Bluetooth status: $(/opt/homebrew/bin/blueutil --power). $(/usr/sbin/networksetup -getairportpower en0)" >> ~/.sleepwatcher.log
~/.wakeup
:
/opt/homebrew/bin/blueutil --power on
/usr/sbin/networksetup -setairportpower en0 on
echo "$(date -Iseconds) -- Wake event detected. Enabled bluetooth and wifi. Bluetooth status: $(/opt/homebrew/bin/blueutil --power). $(/usr/sbin/networksetup -getairportpower en0)" >> ~/.sleepwatcher.log