小智 6
您可以使用它xset -q来检查显示器的状态。到目前为止,我已经看到监视器的 DPMS 状态为“监视器打开”、“监视器关闭”或“监视器处于挂起状态”。您可以编写一个脚本,然后在 xorg 启动后自动启动:
#!/bin/bash
while true; do
xset -q | grep "Monitor is On"
if [ $? -eq 1 ]; then
if [ "`cat /tmp/displaystate`" != "off" ]; then
echo "off" > /tmp/displaystate
# do something when display is switched off
/opt/myScreenOffAction.sh
fi
sleep 1
else
if [ "`cat /tmp/displaystate`" != "on" ]; then
echo "on" > /tmp/displaystate
#do something when display is switched on
/opt/myScreenOffAction.sh
fi
sleep 10
fi
done
Run Code Online (Sandbox Code Playgroud)
要测试您的脚本,您可以使用它xset dpms force suspend来暂停屏幕。
我建议你 grep 为“Monitor is On”,因为上面提到的 off 似乎有不同的状态。
| 归档时间: |
|
| 查看次数: |
1130 次 |
| 最近记录: |