systemd - i3-nagbar 未从 systemd 服务执行(已设置显示和 xauthority)
问题描述
我想在 systemd 中编写一个 cron 作业替换,使用计时器来检查我的电池电量,并在使用 i3-nagbar 低于某个电量时给我一个警告。我查看了 stackoverflow 中的其他问题,但它们都通过设置我所做的 display 和 xauthority 变量来解决。
服务文件:
[Unit]
Description=Low battery warning
[Service]
Environment="DISPLAY=:0" "XAUTHORITY=/home/leon/.Xauthority"
Type=oneshot
ExecStart=/bin/bash /home/leon/.miscellaneous/battery.sh
[Install]
WantedBy=multi-user.target
定时器文件:
[Unit]
Description=Low battery timer
[Timer]
OnUnitActiveSec=5min
OnBootSec=0min
[Install]
WantedBy=timers.target
脚本:
#!/bin/bash
source /sys/class/power_supply/BAT0/uevent
echo $POWER_SUPPLY_STATUS
echo $POWER_SUPPLY_CAPACITY
if [ "$POWER_SUPPLY_STATUS" == "Discharging" ]; then
if [ $POWER_SUPPLY_CAPACITY -lt 30 ]; then
echo "low battery"
/bin/i3-nagbar -t warning -m "Warning: Low Battery" &
elif [ $POWER_SUPPLY_CAPACITY -lt 10 ]; then
systemctl suspend
fi
fi
systemctl 状态 batt_warn.service:
Apr 20 21:32:12 krypton systemd[1]: Starting Low battery warning...
Apr 20 21:32:12 krypton systemd[1]: batt_warn.service: Succeeded.
Apr 20 21:32:12 krypton systemd[1]: Started Low battery warning.
Apr 20 21:32:12 krypton bash[9770]: Discharging
Apr 20 21:32:12 krypton bash[9770]: 27
Apr 20 21:32:12 krypton bash[9770]: low battery
当使用 i3-nagbar 电池电量不足时,它应该给我一个警告。目前脚本正在定期执行,但 nag-bar 似乎没有出现。
解决方案
推荐阅读
- sql - 比较两列时,有没有办法将 Case 函数与 nvarchar 数据类型一起使用?
- google-app-maker - 使用变量计算减法的表达式的语法
- cordova - 如何减少 ionic 4 应用程序加载时间?
- vue.js - 更改路线和调整窗口大小后,Slick Carousel 的高度降至零
- javascript - 如果系统崩溃或用户强行关闭,onbeforeunload 是否有效?
- javascript - 为什么从函数返回的承诺解析为从该函数内部的 .then 返回的值
- dialogflow-es - 如何停止对话流总是返回应该将今天解析为明天的日期
- node.js - Socket.io 导致错误“错误:发送后无法设置标头。”
- wordpress - 如何覆盖子主题中的 woocommerce 小部件?
- java - 使用双括号初始化设置私有字段值