2013-06-21 74 views
1

嗨,我想運行這個腳本,當我打電話給腳本關閉屏幕。如何使用xset關閉屏幕?

Script代碼:

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

這看起來不像一個編程問題(你是寫這個腳本還是隻是從某處抓取它?),但更像是一個X服務器配置問題。您是否真的*看過* xset q'輸出以查看DPMS是否存在? –

+0

試試這個:xset + dpms –

+0

參見http://unix.stackexchange.com/questions/316929/display-is-not-capable-of-dpms-after-gnome-wayland-update – paulie4

回答

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

+0

我也試過,但它顯示相同的錯誤.... – milano

+0

是否支持DPMS? –

0
STATUS_MONITOR=$(xset q | grep "Monitor is" | awk '{print $3}') 

    if [ "$STATUS_MONITOR" == "On" ]; then 

     echo "Status = "$STATUS_MONITOR 

    else 

     echo "Status = "$STATUS_MONITOR 

    fi 

它的工作了我。