You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用BetterTouchTool在Touch Bar显示Magic Mouse电量的技术求助

搞定Touch Bar显示Magic Mouse电量的正确姿势

嘿,你猜得完全对!那个Mouse确实不是正确的应用名称——Magic Mouse的电量信息根本不是通过什么"Mouse"应用获取的,咱们得换个思路来写脚本才行。

我给你准备了两个能在BetterTouchTool里正常跑的方案,随便挑一个用就行:

方案1:用ioreg命令(稳得一批,推荐)

这是调用macOS自带的底层命令直接读取硬件数据,准确率拉满:

set mouseBattery to do shell script "ioreg -c AppleDeviceManagementHIDEventService -r -l | grep -i 'BatteryPercent' | awk '{print $3}'"
if mouseBattery is not "" then
    return mouseBattery & "%"
else
    return "No Mouse"
end if

方案2:纯AppleScript写法(更原生)

要是你偏爱纯AppleScript的路子,试试这个通过系统服务查询蓝牙设备电量的版本:

tell application "System Events"
    set mouseDevices to every Bluetooth device where name contains "Magic Mouse"
    if mouseDevices is not {} then
        return (battery level of item 1 of mouseDevices) & "%"
    else
        return "No Mouse"
    end if
end tell

为啥你原来的脚本不行?

说白了就是那个application "Mouse"根本不存在啊!macOS没给Magic Mouse单独做个叫"Mouse"的应用,所以你的脚本直接跳过了判断逻辑,就返回"no mouse"了。

把上面的任意一个脚本替换到BetterTouchTool里,Touch Bar就能正常显示Magic Mouse的电量啦!

内容的提问来源于stack exchange,提问作者Canato

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 03:25:36