gpt4 book ai didi

linux - 如何使用 xset 关闭屏幕?

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:23:31 25 4
gpt4 key购买 nike

您好,我正在尝试运行此脚本以在调用脚本时关闭屏幕。

脚本代码:

#!/bin/sh
STATUS=`xset -q | grep "Monitor is" | awk '{print $3}'`
if [ "${STATUS}" = "On" ]
then
xset dpms force off
else
xset dpms force on
fi
exit 0

但是当我调用脚本时,出现了这个错误

X Error of failed request:  BadMatch (invalid parameter attributes)
Major opcode of failed request: 142 (DPMS)
Minor opcode of failed request: 6 (DPMSForceLevel)
Serial number of failed request: 10
Current serial number in output stream: 12

最佳答案

#!/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

来自这里:http://systembash.com/content/how-to-turn-off-your-monitor-via-command-line-in-ubuntu/

关于linux - 如何使用 xset 关闭屏幕?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17230192/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com