電子書籍の厳選無料作品が豊富!

デュアルモニタのFedora14の主モニタ上部パネルに置きたいのですが
そのスイッチをシェルスクリプトのランチャによって実現したい
と思っています

[root@fx8120 音楽]# xrandr
Screen 0: minimum 320 x 200, current 3360 x 1080, maximum 8192 x 8192
VGA-0 connected 1440x900+0+0 (normal left inverted right x axis y axis) 410mm x 257mm
 1280x1024 75.0 60.0
 1440x900 75.0* 60.1
 1280x960 60.0
 1152x921 76.0
 1280x800 74.9 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 72.8 75.0 66.7 60.0
 720x400 70.1
HDMI-0 connected 1920x1080+1440+0 (normal left inverted right x axis y axis) 597mm x 336mm
 1920x1080 60.0*+
 1680x1050 60.0
 1600x900 60.0
 1280x1024 75.0 60.0
 1280x960 75.0
 1360x768 59.8
 1152x864 75.0
 1280x720 60.0
 1024x768 75.1 70.1 60.0
 832x624 74.6
 800x600 72.2 75.0 60.3 56.2
 720x480 59.9
 640x480 72.8 75.0 66.7 60.0
 720x400 70.1
[root@fx8120 音楽]#

ですから
主モニタがVGA-0のときには

xrandr --output HDMI-0 --primary

を実行し
主モニタがHDMI-0のときには

xrandr --output VGA-0 --primary

を実行する様にシェルスクリプトを組めばよいのですが
現在主モニタがどちらであるかを知るコマンドが分からなければなりません
どうしたら現在の主モニタを知ることができるでしょうか?

とりあえず今は以下のようにしています

my-monitor:
#!/bin/sh
n=`xrandr|grep -c connected`
if [ $n -ne 2 ]
then
exit
fi
monitor1=`xrandr|grep connected|sed -e "s/ .*//"|sed -e 2d`
monitor2=`xrandr|grep connected|sed -e "s/ .*//"|sed -e 1d`
if [ -e my-toggle ]
then
xrandr --output $monitor1 --primary
rm -f my-toggle
else
xrandr --output $monitor2 --primary
touch my-toggle
fi

よろしくお願いします

A 回答 (1件)

環境変数か、識別用のファイルを作っておいて、随時書き換えでできるとは思います。



ただ、最初に起動する時に、適切に設定しないと機能しませんね。
下手すると、OS再起動後に、識別ファイルが逆になっちゃうこともありそうです。

この回答への補足

回答ありがとうございます

ご指摘の点を考慮して
ログイン時処理スクリプトとトグルスイッチを以下の様にしました

/root/.bash_profile
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
PATH=$PATH:$HOME/bin
export PATH
#追加分#
rm -f my-toggle
monitor=`xrandr|grep connected|sed -n 1p|sed "s/ .*//"`
xrandr --output $monitor --primary


/root/my-monitor:
#!/bin/sh
n=`xrandr|grep -c connected`
if [ $n -ne 2 ]
then
exit
fi
monitor1=`xrandr|grep connected|sed -n 1p|sed "s/ .*//"`
monitor2=`xrandr|grep connected|sed -n 2p|sed "s/ .*//"`
if [ -e my-toggle ]
then
xrandr --output $monitor1 --primary
rm -f my-toggle
else
xrandr --output $monitor2 --primary
touch my-toggle
fi

補足日時:2012/12/09 08:50
    • good
    • 0
この回答へのお礼

最終的には以下の様にしました

/root/.bash_profile:
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
PATH=$PATH:$HOME/bin
export PATH
#今回追加分#
rm -f my-toggle
if [ `xrandr|grep -c connected` -ne 0 ]
then
monitor=`xrandr|grep connected|sed -n 1p|sed "s/ .*//"`
xrandr --output $monitor --primary
fi



/root/my-monitor:
#!/bin/sh
if [ `xrandr|grep -c connected` -eq 2 ]
then
if [ -e my-toggle ]
then
rm -f my-toggle
monitor=`xrandr|grep connected|sed -n 1p|sed "s/ .*//"`
else
touch my-toggle
monitor=`xrandr|grep connected|sed -n 2p|sed "s/ .*//"`
fi
xrandr --output $monitor --primary
fi

お礼日時:2012/12/09 11:03

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!