【发布时间】:2019-11-05 10:58:49
【问题描述】:
我想在我的 Thinkpad X1 上自动设置键盘背光,就像我在旧 XPS13 中使用的那样。在任何按键按下时,背光都应该打开,并且在一定的空闲时间(这里是 30 秒)后背光应该关闭。
我编写了这个基本的 bash 脚本,虽然它每秒通过 xprintidle 轮询一次,但它运行良好,并且可能会消耗一些电池:
#!/bin/bash
function switch {
echo $1 > /sys/devices/platform/thinkpad_acpi/leds/tpacpi\:\:kbd_backlight/brightness
}
while (true); do
sleep 1
last=`xprintidle`
status=`cat /sys/devices/platform/thinkpad_acpi/leds/tpacpi\:\:kbd_backlight/brightness`
[ $last -lt 20000 -a $status -lt 2 ] && switch 2 && continue
[ $last -ge 20000 -a $status -eq 2 ] && switch 1 && continue
[ $last -ge 30000 -a $status -ge 1 ] && switch 0 && continue
done
我想知道是否可以使用一些非轮询方式,例如通过 systemd 或 dbus。
提前谢谢你
【问题讨论】:
-
设置
status,即status=$(</path/to/brightness)时,可以通过从标准输入读取来保存进程。祝你好运。 -
谢谢,好建议 :)
-
顺便说一句,没有必要在子shell中运行
true- 你可以去掉括号。