![打开的列表显示](https://linux22.com/image/145003/%E6%89%93%E5%BC%80%E7%9A%84%E5%88%97%E8%A1%A8%E6%98%BE%E7%A4%BA.png)
我想检查监视器是否打开,以便我可以将输出切换到它。
xrandr --query
将显示所有连接的显示器,无论它们是否打开
xrandr --listmonitors
只会列出正在显示某些内容的监视器。
答案1
https://stackoverflow.com/questions/3433203/how-to-define-if-lcd-monitor-is-turned-on-from-linux-command-line找到shell脚本代码来检查,啦:
#!/bin/bash export DISPLAY=:0.0
if [ $# -eq 0 ]; then
echo usage: $(basename $0) "on|off|status"
exit 1
fi
if [ $1 = "off" ]; then
echo -en "Turning monitor off..."
xset dpms force off
echo -en "done.\nCheck:"
xset -q|grep "Monitor is"
elif [ $1 = "on" ]; then
echo -en "Turning monitor on..."
xset dpms force on
echo -en "done.\nCheck:"
xset -q|grep "Monitor is"
elif [ $1 = "status" ]; then
xset -q|sed -ne 's/^[ ]*Monitor is //p'
else
echo usage: $(basename $0) "on|off|status"
fi