This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Script to control konsole

Tags: konsole konsole konsole
(comma "," separated)
wjessee
Registered Member
Posts
2
Karma
0
OS

Script to control konsole

Wed Dec 16, 2009 6:51 pm
Frequently, I need to log in (ssh) to several servers and issue the same commands (i.e. tail a log file). in kde 3 I used dcop to accomplish this, but with KDE4 -- had a hard time finding a working example. So, here it is!

Basically, this script creates a list of boxes and stores them in an environmental variable (blist). The script takes this list as creates a dialog box, allowing the user to select the hosts to log in to. Next a loop through the selected boxes and:
creates a new tab in konsole --- names the tab the name of the box, echos a message saying you're on that box

Here's the script -- and enjoy

Code: Select all
MYCOMMAND='ssh '
blist="serverBox1.example.com serverBox2.example.com serverBox3.example.com serverBox4.example.com"
for i in $blist ; do
   menulist="$menulist $i $i on"
done
boxlist=$(kdialog --separate-output --checklist  "Select all boxes to open" $menulist)
cursession=`qdbus org.kde.konsole /Konsole currentSession`
for i in $boxlist
do
  echo $i
  session=$(qdbus org.kde.konsole /Konsole  newSession)
  qdbus org.kde.konsole /Sessions/${session} setTitle 1 $i
  qdbus org.kde.konsole /Sessions/${session} sendText "${MYCOMMAND}"
  qdbus org.kde.konsole /Sessions/${session} sendText "${i}"
  qdbus org.kde.konsole /Sessions/${session} sendText "
   "
  qdbus org.kde.konsole /Sessions/${session} sendText "
   "
  qdbus org.kde.konsole /Sessions/${session} sendText "echo Running on ${i}
  "
  qdbus org.kde.konsole /Sessions/${session} setMonitorActivity true
done
kay_de_e
Registered Member
Posts
16
Karma
0

Re: Script to control konsole

Thu Jan 07, 2010 11:46 am
thank you very much! this helped me a lot!


kay_de_e, proud to be a member of KDE forums since 2008-Dec.
User avatar
leprosys
Registered Member
Posts
6
Karma
0
OS

Re: Script to control konsole

Tue Mar 16, 2010 12:39 am
Thank you is what I was looking.
kdeforumsuser2010
Registered Member
Posts
59
Karma
0
OS

Re: Script to control konsole

Tue Mar 16, 2010 2:17 pm
Regarding "names the tab the name of the box", see:
http://www.linuxjournal.com/content/update-controlling-konsole-dbus
As I've begun to use that script for setting up my konsoles I, like others, have discovered that the tab title that you set with dbus doesn't stick. This short note shows you a workaround to make your tab titles stay put.
...
konsole has two types of tab titles: one that's set with the function setTitle() and another that's set with the function setUserTitle(). If you don't set the one that's set with setUserTitle() then the tab title changes back to the default when you use the session. The problem is that the dbus interface allows you to call setTitle() but it does not allow you to call setUserTitle().
wjessee
Registered Member
Posts
2
Karma
0
OS

Re: Script to control konsole

Fri Feb 24, 2012 10:49 pm
An update. Finally discovered a way to set the titles on the tabs with the name of the box. First, I create an environment variable SHORTNAME (a short name of the box I'm ssh'ing to), then in the script add these 2 lines:

qdbus $KONSOLE_DBUS_SERVICE /Sessions/${session} setTabTitleFormat 0 $SHORTNAME
qdbus $KONSOLE_DBUS_SERVICE /Sessions/${session} setTabTitleFormat 1 $SHORTNAME
dargaud
Registered Member
Posts
22
Karma
0
OS

Re: Script to control konsole

Fri Sep 25, 2015 2:09 pm
This script seems to be exactly what I'm looking for, except that:
Code: Select all
$ qdbus org.kde.konsole
Service 'org.kde.konsole' does not exist.

I've seen similar (?) examples use $KONSOLE_DBUS_SERVICE instead.
I'm on KDE 4 (4.14 actually).


Bookmarks



Who is online

Registered users: Bing [Bot], daret, Google [Bot], sandyvee, Sogou [Bot]