On 09/26/2007 10:00 PM, Nguyen, Cuong K. wrote:
Hi all,
I have a problem - basically with some bash codes. I have dual screen
and one mouse, and I want to switch my mouse back and forth from screen
1 to screen 2 etc by pressing a keyboard. In order to do that, I did the
following:
1. install switchscreen, then by typing "switchscreen 0" or
"switchscreen 1" will switch me to Desktop 0 or 1.
2. typing "switchscreen 0" or 1 is annoying, then I create a script
/bin/switchnow like below:
########################
#!/bin/bash
case $DISPLAY in
:0.0 ) exec switchscreen 1
;;
:0.1 ) exec switchscreen 0
esac
########################
and make it executable, then now by typing just switchnow on terminal, I
will move back and forth from Desktop 0 and 1. Obviously it works :)
3. I install xbindkeys, find the corresponding key and create
~/.xbindkeysrc as follow
########################
# shortcut 2
"switchnow"
m:0x0 + c:118
########################
Okey, everything seems to be done now. I press the key, and from Desktop
0, I am switched to Desktop 1. But when I press the same key again,
nothing happens. :(
It *seems* that when xbindkeys works and executes switchnow, the value
of DISPLAY is kept unchanged to be :0.0. But in desktop 1, open terminal
and when I type "echo $DISPLAY" then I get :0.1. I guess I wrote the
script incorrectly, or did I miss something here?
I do not know programming, and do not know bash either. So please do not
blame me if I am too noob to bash :D.
Thanks a million,
KC.
You're probably right that the DISPLAY is always :0.0. You need another
way to toggle between 0 and 1. Try this:
#!/bin/bash
swfile=/tmp/sw-file
if [ ! -f $swfile ]; then echo 0 > $swfile ; fi
echo $(( ! `cat $swfile` )) > $swfile
echo exec switchscreen `cat $swfile`
Note that I just echo-ed the command because I don't have switchscreen
installed. The $(( ... )) syntax allows you to evaluate mathematical
expressions. Read "man bash"
HTH
--
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]