环境:UBUNTU 22.04
当主机无人使用的时候,我们想显示一些统计报表。
那么可以通过如下方式实现:
1. 在 设置 中, 关闭 屏幕变暗,从不 熄屏
2. 在 启动应用程序 中设置如下脚本路径。
3. 脚本
#!/bin/sh # Wanted trigger timeout in milliseconds. IDLE_TIME=$((1*60*1000)) # 1 minutes GRAFANA_URL=http://192.168.1.86:3000 triggered=false windowid=-1 while [ true ]; do idle=$(xprintidle) if [ $idle -le 200 ]; then if $triggered; then echo "kill Grafana" >> ~/log.txt (wmctrl -a firefox) sleep 0.2 tabname=$(xdotool getwindowname $windowid) echo $tabname >> ~/log.txt if echo "$tabname" | grep -q -E "Grafana — Mozilla Firefox$"; then triggered=false xdotool key Ctrl+w fi fi fi if [ $idle -ge $IDLE_TIME ]; then if ! $triggered; then triggered=true (firefox -url $GRAFANA_URL &) #sleep 2 secs to wait for firefox start sleep 2 windowid=$(xdotool search --sync --onlyvisible --name firefox) (xdotool getwindowname $windowid) #(wmctrl -a firefox && sleep 0.1 && xdotool key F11) fi fi sleep 0.1; # 100 ms done
该脚本中使用了 xprintidle
xdotool
wmctrl 工具,请先使用apt-get安装。