美文网首页
解决黑苹果Ventura蓝牙睡眠后有时候不工作问题

解决黑苹果Ventura蓝牙睡眠后有时候不工作问题

作者: Start_8528 | 来源:发表于2023-11-12 11:41 被阅读0次

    安装完黑苹果后用的免驱网卡BCM94360CS2  自动睡眠后,后出现蓝牙不能用的情况。必须把蓝牙开关一下才行。经过网上的搜索目前问题已经解决

    准备工作

    下载sleepwatcher

    推荐官网直接下载,地址: https://www.bernhard-baehr.de/。(地址可能需要翻墙才能访问)

    安装blueutil

    blueutil是一个蓝牙工具,可以通过命令打开和关闭蓝牙,推荐使用homebrew下载 

    brewinstall blueutil

    安装sleepwatcher

    首先通过终端进入sleepwatcher的文件夹,以我的为例,版本为sleepwatcher_2.2.1

    cd sleepwatcher_2.2.1sudo cp./sleepwatcher /usr/local/sbinsudo cp./sleepwatcher.8 /usr/local/share/man/man8#创建数据文件夹,这个可以自定义,如果选择不同的路径,下面的路径也必须跟着修改mkdir~/.sleep

    紧接着创建2个脚本,一个用于启动蓝牙,一个用于关闭,分别把这两个文件放到~/.sleep/

    下面是rc.sleep文件,用于睡眠时关闭蓝牙

    #!/bin/bash# rc.sleep# Stop Bluetooth Module on Mac OS X## Requires Blueutil to be installed: http://brewformulas.org/blueutilBT="/usr/local/bin/blueutil"log(){# logger -p notice -t bt_restarter "$@"echo"$@">>~/.sleep/sleepwatcher.log}err(){echo"$@">&2echo"$@">>~/.sleep/sleepwatcher.log# logger -p error -t bt_restarter "$@"}log""log"sleep at $(date+"%Y-%m-%dT%H:%M:%S")"if[-f"$BT"];then

    if[[$("$BT"-p)==0]];then

    log"Bluetooth is off, nothing to do."else

    log"Bluetooth on, stopping ..."($("$BT"-p0)&> /dev/null&&echo"Bluetooth Module stopped")||(err"Couldn't stop Bluetooth Module"&&exit 1)log"Successfully stoped Bluetooth"&&exit 0fi

    else

    err"Couldn't find blueutil, please install http://brewformulas.org/blueutil"&&exit 1fi

    下面是rc.wakeup,用户唤醒时打开蓝牙

    #!/bin/bash# rc.wakeup# Restart Bluetooth Module on Mac OS X## Requires Blueutil to be installed: http://brewformulas.org/blueutilBT="/usr/local/bin/blueutil"log(){# logger -p notice -t bt_restarter "$@"echo"$@">>~/.sleep/sleepwatcher.log}err(){echo"$@">&2echo"$@">>~/.sleep/sleepwatcher.log# logger -p error -t bt_restarter "$@"}log"wakeup at $(date+"%Y-%m-%dT%H:%M:%S")"if[-f"$BT"];then

    if[[$("$BT"-p)==0]];then

    log"Bluetooth is off, Starting Bluetooth..."($("$BT"-p1)&> /dev/null&&echo"Bluetooth Module started")||(err"Couldn't start Bluetooth Module"&&exit 1)else

    log"Bluetooth on, restarting ..."($("$BT"-p0)&> /dev/null&&echo"Bluetooth Module stopped")||(err"Couldn't stop Bluetooth Module"&&exit 1)($("$BT"-p1)&> /dev/null&&echo"Bluetooth Module started")||(err"Couldn't start Bluetooth Module"&&exit 1)log"Successfully restarted Bluetooth"&&exit 0fi

    else

    err"Couldn't find blueutil, please install http://brewformulas.org/blueutil"&&exit 1fi

    下一步是给这两个文件添加上可执行权限

    cd~/.sleepchmod u+x rc.sleep rc.wakeup

    成功后,创建文件 ~/Library/LaunchAgents/de.bernhard-baehr.sleepwatcher.plist,粘贴下面内容

    <?xml version="1.0" encoding="UTF-8"?><!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"><plistversion="1.0"><dict><key>Label</key><string>de.bernhard-baehr.sleepwatcher</string><key>ProgramArguments</key><array><string>/usr/local/sbin/sleepwatcher</string><string>-V</string><string>-s ~/.sleep/rc.sleep</string><string>-w ~/.sleep/rc.wakeup</string></array><key>RunAtLoad</key><true/><key>KeepAlive</key><true/></dict></plist>

    最后一步,执行命令

    这里是进入~/Library/LaunchAgents 目录下执行下面的命令

    launchctl load de.bernhard-baehr.sleepwatcher.plist

    执行完后,可能会弹窗请求授权,这时正常通过即可,这时你可以直接直接选择睡眠和唤醒,查看效果。

    你可以通过执行命令cat ~/.sleep/sleepwatcher.log查看睡眠和唤醒时启动和关闭蓝牙的日志。

    上面的步骤转载https://wiyi.org/fixed-sleep.html

    相关文章

      网友评论

          本文标题:解决黑苹果Ventura蓝牙睡眠后有时候不工作问题

          本文链接:https://www.haomeiwen.com/subject/fuolwdtx.html