Lubuntu:切换显示的热键

我是Linux的新手,也是bash脚本的新手。

我正在尝试在我的旧华硕EEE上网本上设置Fn-F5键,以在内部和外部显示器之间切换。

~/bin/toggle_displays.sh创建bash脚本:

  #!/bin/bash if (xrandr | grep "VGA1 disconnected"); then # external monitor not connected: do nothing xrandr --output LVDS1 --auto --output VGA1 --off else # external monitor connected: toggle monitors if (xrandr | grep -E "LVDS1 connected (primary )?\("); then xrandr --output LVDS1 --auto --output VGA1 --off else xrandr --output LVDS1 --off --output VGA1 --auto fi fi 

将热键添加到~/.config/openbox/lubuntu-rc.xml 部分:

 ...   ~/bin/toggle_displays.sh   ... 

问题非常奇怪:当内部显示处于活动状态时,切换到外部始终有效。 但是当外部处于活动状态时,切换只会在内部显示屏上显示带有鼠标光标的黑屏。 更令人惊讶的是,如果我从终端运行脚本而不是热键,后一个开关有时会起作用。

可能是什么问题? 我怎么可能调试这个?

作为旁注,从终端运行脚本以从外部显示器切换到内部显示器将LVDS1 connected primary (normal left inverted right x axis y axis)打印到终端。 如果我在脚本中不echo ,为什么会这样?

编辑:这是我的xrandr输出(使用外部监视器):

 Screen 0: minimum 8 x 8, current 1680 x 1050, maximum 32767 x 32767 LVDS1 connected primary (normal left inverted right x axis y axis) 1024x600 60.0 + 800x600 60.3 56.2 640x480 59.9 VGA1 connected 1680x1050+0+0 (normal left inverted right x axis y axis) 473mm x 296mm 1680x1050 60.0*+ 1600x1200 60.0 1280x1024 75.0 60.0 1440x900 75.0 59.9 1280x800 59.8 1152x864 75.0 1024x768 75.1 70.1 60.0 832x624 74.6 800x600 72.2 75.0 60.3 56.2 640x480 75.0 72.8 66.7 60.0 720x400 70.1 VIRTUAL1 disconnected (normal left inverted right x axis y axis) 

我自己写了一个bash脚本,可以在笔记本电脑的屏幕和外部屏幕之间切换。 它会检查哪个屏幕处于打开状态,将其关闭并以其原始分辨率打开另一个屏幕。 好消息是。 它不需要知道屏幕的名称,因为它们是从xrandr收集的。

 #!/bin/bash #Toggles between two screens. Assuming only one external screen is connected monitors=`xrandr | grep -P ' connected' | grep -o '^[^ ]*'` set -- "$monitors" #monArr contains an array of the id's of the connected screens declare -a monArr=($*) #onMon holds the id of the *first* on screen found onMon=`xrandr --listmonitors | head -2 | grep -oP "[a-zA-Z]*-[0-9]$"` #offMon holds the id of the other monitor, which is not on if [ "$onMon" = "${monArr[0]}" ] then offMon=${monArr[1]} else offMon=${monArr[0]} fi #Switches the on screen off and vice versa xrandr --output $offMon --auto --output $onMon --off