Wednesday, November 30, 2005

scripting up some tabs in kde's konsole app


[root@moby bin]$ cat bipcons.sh
#!/bin/sh

SESSIONS="
d44
co-04
c62-29
co-02
co-05
d84-1
d84-2
"

KONSOLE=`dcopclient $KONSOLE_DCOP`
CURSESSION=$KONSOLE_DCOP_SESSION
for A in $SESSIONS; do
NEWSESSION=`dcop $KONSOLE konsole newSession $A`
dcop $KONSOLE $NEWSESSION renameSession $A
# your command here on the next line!
dcop $KONSOLE $NEWSESSION sendSession "console $A"
done
dcop $CURSESSION closeSession



The above shell script I have saved to a icon on my kde desktop. The icon properties run this in the command section:

/usr/local/bin/konsole --script -e ~/bin/bipcons.sh

Basically it opens a new tab for each entry in $SESSIONS, assigns the tab name to that entry ($A) and then runs a command on that entry as well. In this example, the remote console app (http://www.conserver.com). Of course that app could be anything, like ssh.

Very useful stuff. Took me a long time to dig up this information on the web, so I'm posting it here for posterity.

2 comments:

  1. Does not work (anymore?)

    konsole --script -e bipcons.sh
    konsole: WARNING: Unable to open a pseudo teletype!
    Uh oh.. can't get terminal attributes.

    ReplyDelete
  2. That's strange. This script certainly works on KDE 3.5.x and above. You might try debugging just konsole -e (some simple shell script) or xterm -e (some simple shell script) and see if you have the same problem. That would point the finger at your X,OS, or tty setup rather than KDE.

    Note that this type of DCOP invocation in my research was different than it was written here for earlier KDE versions. I only posted the working code.

    ReplyDelete