ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A
Ask Your Question

How can i automate my ROS work session environment?

asked 2012-09-27 15:03:04 -0600

TurtleBot_Fan gravatar image

While working more extensively (with ROS using Ubuntu Precise 12.04), I find myself repeatedly having to invoke several applications such as an editor(s), Nautilus, multiple terminals, Tomboy Notes, a simulation environment(s) and a good browser(s) just to start up my work session.

Moreover, there are times when I must repetitiously type in terminal commands to recreate the state of my work so I may continue where I left off. There is the idea of computer system hibernation, but I'd rather boot freshly before each work session.

Is there a way to automate a "ROS startup work session environment" (if you will)?.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2012-09-27 15:14:59 -0600

TurtleBot_Fan gravatar image

updated 2012-09-27 15:46:40 -0600

This is my solution. The automation is done by a python script using the "subprocess" command and the "xdotool" command.

The code is rustic, but it works. Here is the file:


import subprocess
import shlex
import os
import time
from Xlib import X, display

# The following was installed using Ubuntu Software Center
# python-xlib
# xdotool

def TrackMouseCoordinates():
  #import time
  #from Xlib import X, display

  while True:
    d = display.Display()
    s = d.screen()
    root = s.root
    print b["root_x"], b["root_y"]

def GetActiveWindowTitle():
    return subprocess.Popen(["xprop", "-id", subprocess.Popen(["xprop", "-root", "_NET_ACTIVE_WINDOW"], stdout=subprocess.PIPE).communicate()[0].strip().split()[-1], "WM_NAME"], stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()[0].strip().split('"', 1)[-1][:-1]

def GetWindowIdOfOpenActiveWindow(windowName):
    p = subprocess.Popen(["xdotool", "search", "--name",
    out =
    idwin = out.split("\n")[0]
    return idwin

def OpenAllDesiredTerminalsAndReturnActiveTerminal():
  # create terminals
  #activeWinTitle = ""
  # geometry is widthxheight+x+y   50x10+1935+20["xdotool", "exec", "gnome-terminal", "--geometry=100x10+1935+20", "--working-directory=sam"])["xdotool", "exec", "gnome-terminal", "--geometry=40x5+20+20", "--working-directory=SQ_bin"])
  #time.sleep(5) # Necessary to let processes complete
  # click on a terminal to activate it (activating sam terminal at 705,37)["xdotool", "mousemove", "705", "37","click", "1"])
  #activeWinTitle = GetActiveWindowTitle()
  #print 'Active window title: ', activeWinTitle
  #return activeWinTitle

def sendKeystrokesToWindow(windowID,keystrokes):
    #print "sending command %s " %command["xdotool", "key", "%s" % command ])["xdotool", "type", "--window", "windowID", keystrokes])

def openROSrelatedApplications():
  # Home Folder GUI["xdotool", "exec", "nautilus"])
  # Chromium Browser["xdotool", "exec", "chromium-browser"]) #, "%U"])
  # Tomboy Notes["xdotool", "exec", "tomboy", "--search"]) #, "%U"])
  # 4 Terminals

# open applications
# create terminals
# get window id of active terminal
# send keystrokes to active terminal
#sendKeystrokesToWindow(terminID,"ls\n") #roscd beginner_tutorials
edit flag offensive delete link more


This feels pretty complicated. What's the reason for not writing a simple shell script?

Lorenz gravatar image Lorenz  ( 2012-09-27 23:02:27 -0600 )edit

No real reason. I just felt a python script would be fun.

TurtleBot_Fan gravatar image TurtleBot_Fan  ( 2012-09-28 09:37:18 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools



Asked: 2012-09-27 15:03:04 -0600

Seen: 470 times

Last updated: Sep 27 '12