Rad*_*anu 14
您可以使用acpiwith-a参数。要查看它是如何工作的,请在您的终端中运行:
acpi -a
Run Code Online (Sandbox Code Playgroud)
默认情况下,acpi软件包未安装在 Ubuntu 中,但使用以下命令从终端安装非常简单快捷:
sudo apt-get install acpi
Run Code Online (Sandbox Code Playgroud)
然后,在您的脚本中,您可以使用例如:
ac_adapter=$(acpi -a | cut -d' ' -f3 | cut -d- -f1)
if [ "$ac_adapter" = "on" ]; then
notify-send "AC Adapter" "The AC Adapter is on."
else
notify-send "AC Adapter" "The AC Adapter is off."
fi
Run Code Online (Sandbox Code Playgroud)
要使脚本在启动时运行,只需在您的 crontab 列表中添加一个新条目(使用crontab -e命令),如下所示:
@reboot DISPLAY=:0.0 /path/to/your/script
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6231 次 |
| 最近记录: |