使用BetterTouchTool在触摸栏中显示魔术键盘和魔术鼠标电池

时间:2019-01-04 15:40:21

标签: applescript

基于以下问题:Display Magic Mouse Battery in Touch bar using BetterTouchTool

我正在使用此BetterTouchToll使我的触摸栏更加有趣。

他接受一些Apple脚本以提高动态性,所以我开始研究这些脚本。

现在,我想在触摸栏中显示魔术鼠标和魔术键盘电池,为此,我正在尝试使用此代码,但无法正常工作。

set finalDevice to do shell script "ioreg -c AppleDeviceManagementHIDEventService | grep '\"Product\" =' | tail -2"

if finalDevice contains "Magic Keyboard" then
    if finalDevice contains "Magic Mouse" then
        set remaining to do shell script "ioreg -c AppleDeviceManagementHIDEventService | grep BatteryPercent | tail -2 | sed 's/[^[:digit:]]//g'"
        "⌨️ " & remaining & "%" & "️" & remaining & "%"
    else
        set remaining to do shell script "ioreg -c AppleDeviceManagementHIDEventService | grep BatteryPercent | tail -1 | sed 's/[^[:digit:]]//g'"
        "⌨️ " & remaining & "%"
    end if
else if finalDevice contains "Magic Mouse" then
    set remaining to do shell script "ioreg -c AppleDeviceManagementHIDEventService | grep BatteryPercent | tail -1 | sed 's/[^[:digit:]]//g'"
    "️" & remaining & "%"
else
    "nothing"
end if

问题

  • 当我在两台设备上同时使用remaining时,它会显示“一个电池电量” +跳线+“其他电池电量”。

我的答案应该是:"⌨️ 45%️39%"

现在是:

"⌨️ 39
45%️39
45%"
  • finalDevice上,鼠标或键盘可能是最后一个。所以我需要以某种方式检查它的位置;

这不行:"⌨️ 39%️45%"

0 个答案:

没有答案