Magic Trackpad 电量检查脚本

2017-05-26 17:49:44 +08:00
 AntonChen

效果:

http://i.imgur.com/WGB0Rwv.jpg

使用:

根据需求设置定时任务,如 */10 * * * * bash $HOME/.scripts/CheckTrackpadBattery.sh > /dev/null 2>&1

脚本:

#!/bin/bash
# Create Date: 2017-05-26 17:03:49
# Last Modified: 2017-05-26 17:31:52
# Author: Anton Chen
# Email: contact@antonchen.com
export PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
system_profiler SPBluetoothDataType|grep -A 24 'Devices'|grep -q Trackpad
if [ $? -ne 0 ]; then
    echo "Trackpad 未连接"
    exit 1
fi

batteryLevel=$(system_profiler SPBluetoothDataType|grep -A 24 'Devices'|grep Battery|awk -F"[:| |%]+" '{print $4}')
if [ $batteryLevel -lt 20 ]; then
    osascript -e "tell application \"System Events\" to display notification \"电量低,剩余 $batteryLevel%\" with title \"Magic Trackpad 2\" sound name \"Submarine\""
fi

Gayhub

https://github.com/antonchen/scripts/blob/master/macOS/CheckTrackpadBattery.sh

1998 次点击
所在节点    macOS
7 条回复
chairuosen
2017-05-26 17:57:12 +08:00
........topbar 蓝牙的下拉菜单里能看电量的
AntonChen
2017-05-26 17:59:18 +08:00
@chairuosen 电量低有提示么?我没发现有。
chairuosen
2017-05-26 18:04:55 +08:00
@AntonChen 触摸板有没有我没印象了,不过蓝牙鼠标键盘电量低是有提示的,触摸板应该也有
thekoc
2017-05-26 21:55:12 +08:00
@AntonChen 有提示。只不过貌似要非常低才有
maemolee
2017-05-27 00:27:38 +08:00
触摸板和键盘在 10%左右电量(左右)就会推送充电通知的。
AntonChen
2017-05-27 08:29:40 +08:00
@maemolee 好吧,我没用到过 10%
ashfinal
2017-05-27 13:14:53 +08:00
@AntonChen。。。笔记本电池好像也是 10%

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/364056

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX