gpt4 book ai didi

bash - 如何使用 shell 脚本和 'xrandr' linux 命令打开/关闭屏幕监视器?

转载 作者:行者123 更新时间:2023-12-04 16:16:27 24 4
gpt4 key购买 nike

我正在尝试使用键绑定(bind)在 Ubuntu14.04 中打开和关闭屏幕监视器。
我尝试了以下 shell 脚本:

#!/bin/sh 
output=$(xrandr | grep ' connected ' | awk '{print $1}' | head -1)
screenSize=$(xrandr | awk 'BEGIN {foundOutput=0}
/ '$output' / {foundOutput=1}
/\*\+/ {print $1}
/^[^ ]/ {if(foundOutput) exit 0}')
if [ "$screenSize" != "" ]; then
xrandr --output $output --fb $screenSize --off
espeak "Monitor off"
else
xrandr --output $output --auto
espeak "Monitor on"
fi

1) 上述脚本在 Ubuntu 10.04 中运行良好,但在 Ubuntu 14.04 中无法正常运行。

2) 我将此脚本绑定(bind)到 Ctrl+Alt+M 键上。

3) 当我按下这个键绑定(bind)时它会关闭显示器但是我再次按下这个键绑定(bind)它不会启动屏幕监视器。

4)我尝试运行这个命令

xrandr --output $output --auto

xrandr --output LVDS-1 --auto

但什么也没发生。

5) 我也试过这个命令

xset dpms force off

但如果按下任何键,它将启动屏幕监视器。

那么我应该怎么做才能使用 shell 脚本打开或关闭屏幕监视器?

最佳答案

笔记本电脑通常会有自己的屏幕键绑定(bind),可以打开和关闭显示屏。如果您的笔记本电脑没有这样的 key ,请尝试搜索 xrandr 以外的程序,这些程序可以执行您想要的操作。 Ubuntu 的默认屏幕保护程序可以分配一个键,该键将自动关闭并锁定屏幕。

  1. 导航系统设置 > 键盘 > 快捷方式 > 系统。
  2. 单击 +,将您的自定义快捷方式命名为您想要的任何名称,然后将其作为命令 gnome-screensaver-command -la
  3. 点击应用,然后分配您要添加的快捷方式。

这些说明也可以在这里找到(带图片):askubuntu.com/questions/446601/how-can-i-lock-and-blank-the-screen-from-the-keyboard-in-14-04您甚至可以让 xrandr 与设置管理器一起工作,但我不知道。

关于bash - 如何使用 shell 脚本和 'xrandr' linux 命令打开/关闭屏幕监视器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30251741/

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