Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8303903
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T17:39:20+00:00 2026-06-08T17:39:20+00:00

I’m writing a script to automate work environment preparation. I need to open 4

  • 0

I’m writing a script to automate work environment preparation.
I need to open 4 terminal windows, arrange them and execute commands in each of them.

It works, but sometimes I get nasty fails – 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 the other 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 guess it depends on CPU load, cause I have really big .bashrc processed by ATOM and its load is high during script processing.

I use wait and sleep and special order of open_lxterminal_execute_hold() function invocations in the script toexecute simple simple commands first. That minimizes errors, but doesn’t prevent them at all.

What would you suggest to get stable result regardless of CPU load(whatever)? It would be great to get rid of sleeps as well.

#!/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 repeating charatcers?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T17:39:21+00:00Added an answer on June 8, 2026 at 5:39 pm

    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 may notice, I’ve commented some lines for testing, so you should remove the trailing ‘#‘ from the commented lines before running the script on your system.
    The trick I’ve used is to start in each terminal a new shell with the “–rcfile” option.
    This way, there is no need to use the “xdotool”, “wait” and “sleep” commands.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
In my XML file chapters tag has more chapter tag.i need to display chapters
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
I need a function that will clean a strings' special characters. I do NOT
I am writing an app with both english and french support. The app requests
I have thousands of HTML files to process using Groovy/Java and I need to
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
That's pretty much it. I'm using Nokogiri to scrape a web page what has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.