1

Hi i am trying to run this script that turn off the screen when i call the script.

Script code:

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

But when i call the script, i am getting this error

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
4

2 に答える 2

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

于 2013-06-21T07:55:57.253 に答える