`xdotool type` - random repeat of characters

I am writing a script to automate the preparation of a production environment. I need to open 4 terminal windows, arrange them and execute commands in each of them.

This works, but sometimes I disgustingly refuse - xdotool type randomly repeats some characters :

 rvm use ruby-1.99999999999999999999999999999999.3-p194@ro && rails c ~/my_src/ruby_apps/ro > rvm use ruby-1.99999999999999999999999999999999.3-p194@ro && rails c ruby-1.99999999999999999999999999999999.3-p194 is not installed. To install do: 'rvm install ruby-1.99999999999999999999999999999999.3-p194' ~/my_src/ruby_apps/ro > 

or in another window:

 tail -fn 100 looooooog/thin.0.log ~/my_src/ruby_apps/ro > tail -fn 100 looooooog/thin.0.log tail: could not open ยซlooooooog/thin.0.logยป for reading: No such file or directory tail: no more files ~/my_src/ruby_apps/ro > 

I think it depends on the processor load, because I have a really big .bashrc processed by ATOM and its load is high during script processing.

I use wait and sleep and the special order t2> invocations in the script to execute simple simple simple commands. This minimizes errors, but does not bother them at all.

What would you suggest to get a stable result regardless of CPU utilization (whatever)? It would be great to get rid of sleep .

 #!/bin/bash # # prepares work environment for rails project # Opens lxterminal with title if windows with such title # doesn't exist, executes command and stays open. # Otherwise does nothing. # function open_lxterminal_execute_hold(){ local winid=`xwininfo -name $title 2>/dev/null |grep 'Window id:' |cut -d" " -f4` if [ -n "$winid" ]; then echo "Window for title '$title' exists with '$winid'" else lxterminal -t $title sleep 1 wmctrl -i -a "$winid" # bring the window to front, activate wait xdotool type "$command" wait xdotool key Return # run the command wait fi } pkill devilspie cd ~/my_src/ruby_apps/ro # TODO param title='rails-commandline'; command='ls'; open_lxterminal_execute_hold title='rails-development.log'; command='tail -fn 100 log/development.log'; open_lxterminal_execute_hold title='rails-user_case'; command='tail -fn 100 log/thin.0.log'; open_lxterminal_execute_hold sleep 5 title='rails-console'; command='rvm use ruby-1.9.3-p194@ro && rails c'; open_lxterminal_execute_hold /usr/bin/devilspie -a 2>/dev/null & # arrange windows 

UPDATE How to prevent xdotool characters from repeating?

+4
source share
4 answers

Here is another solution tested and working on my Ubuntu 11.04 system:

 #!/bin/bash function open_lxterminal_execute_hold() { xwininfo -name $1 > /dev/null 2>&1 if [ $? -eq 0 ]; then echo "Window for title '$1' already exists" else t=$(tempfile) echo ". ~/.bashrc" > $t echo "$2" >> $t lxterminal -t $1 -e "$SHELL --rcfile $t" & fi } #pkill devilspie #cd ~/my_src/ruby_apps/ro open_lxterminal_execute_hold 'rails-commandline' 'ls' open_lxterminal_execute_hold 'rails-development' 'tail -fn 100 log/development.log' open_lxterminal_execute_hold 'rails-user_case' 'tail -fn 100 log/thin.0.log' #open_lxterminal_execute_hold 'rails-console' 'rvm use ruby-1.9.3-pl94@ro && rails c' #devilspie -a 2>/dev/null & 

As you can see, I commented on some lines for testing, so before you run the script on your system, you must remove the final " # " from the commented lines.
The trick I used was to launch a new shell in each terminal with the parameter - rcfile ".
Thus, there is no need to use the "xdotool", "wait" and "sleep" commands.

+2
source

Here is a workaround that xdotool generally avoids. On the plus side, I think it's pretty simple. On the negative side, it does not work with lxterminal - although it works with other terminals such as xterm and gnome-terminal.

For what it's worth, here is the idea:

Let bashrc run the appropriate commands based on the value of the title environment variable:

You can do this by adding something like the following to your .bashrc:

 case "$title" in rails-development.log) ls ;; rails-commandline) tail -fn 100 /var/log/syslog ;; *) ;; esac 

And then in the script you can use

 function open_terminal_execute_hold() { local winid=`xwininfo -name $title 2>/dev/null |grep 'Window id:' |cut -d" " -f4` if [ -n "$winid" ]; then echo "Window for title '$title' exists with '$winid'" else gnome-terminal -t "$title" & fi } cd /tmp # TODO param export title='rails-commandline' && open_terminal_execute_hold & export title='rails-blah' && open_terminal_execute_hold & export title='rails-development.log' && open_terminal_execute_hold & 

For some reason, lxterminal uses only the first value for title , ignoring subsequent changes to its value.

+2
source

Actually, I found anoter solution. I found that I was using an old version of 2009 from the ubuntu deb package. The latest version of xdotool that I installed from sources allows you to use the new command line param --delay <value> , which when used with 0 --delay 0 prevents the characters from repeating. So now the function looks like this:

 function open_lxterminal_execute_hold(){ local winid=`xwininfo -name $title 2>/dev/null |grep 'Window id:' |cut -d" " -f4` if [ -n "$winid" ]; then echo "Window for title '$title' exists with '$winid'" else lxterminal -t "$title" sleep 1 wmctrl -i -a "$winid" xdotool type --delay 0 "$command" xdotool key Return fi } 

good luck, guys!

0
source

Instead, you can use the xte command line xte . It does the same job, but without random key stickiness.

0
source

All Articles