On 10/22/2019 12:38 PM, Michael wrote:
Is this possible?
Have several tabs open in Konsole. Upon (re)login to TDE have program A
automatically run in tab A, program B automatically run in tab B, program C
automatically run in tab C?
Yes, this is quite possible and you use dcop to do it. I have console with
10-tabs (5-local/5-remote) session that I restore each time I start TDE/KDE. I
wrote a script (that I have assigned to a button on the QuickLaunch menu to
invoke)
The script is just a bash script that talks to dcop which talks to konsole.
Simple really:
#!/bin/bash
kid=$(dcop "konsole*") ## get konsole_id (if konsole running)
test -z "$kid" && { ## if not running
kstart konsole --script ## start 1st session (add --iconify to start
minimized)
# kstart --iconify konsole --script ## start 1st session minimized)
sleep 1 ## wait for start
kid=$(dcop "konsole*") ## get konsole_id
declare -i tries=0
while test -z "$kid" -a "$tries" -lt '10'
do
sleep 0.5
kid=$(dcop "konsole*")
((tries++))
done
test "$tries" -eq '10' && {
printf "error: kstart konsole failed.\n"
exit 1
}
}
Then you can use ps and awk to check that the only konsole running is the
one you just started (and you can distinguish between them) Switch to the 1st
konsole session:
sid1=$(dcop $kid konsole sessionId 1) ## get 1st session_id
sid=$(dcop $kid konsole currentSession) ## get currentSession
## validate 1st session active
test "$sid" != "$sid1" && {
dcop $kid konsole activateSession "$sid1" ## switch to 1st session
printf "warning: sid (%s) != sid1 (%s)\n" "$sid" "$sid1"
>&2
sid="$sid1"
}
Then I simply have an array of ssh_sessions I loop over opening in a new tab
(session) in konsole. Similar to:
## open rename/open remaining sessions
while test "$idx" -lt "$scount"
do
name=${sessions[$((idx++))]} ## get session name & command
cmd=${sessions[$((idx++))]}
dcop $kid $sid renameSession "$name" ## set name & send cmd
sleep 0.1
dcop $kid $sid sendSession "$cmd"
sleep 0.1
if test "$sidx" -lt "$nsessions" ## session index -lt
current number
then
dcop $kid konsole nextSession ## switch to nextSession & get id
sid=$(dcop $kid konsole currentSession)
elif test "$idx" -lt "$scount"
then
((nsessions++))
sid=$(dcop $kid konsole newSession) ## create new session
while test "$(dcop $kid konsole sessionCount 2>/dev/null)" -lt
"$nsessions"
do
sleep 0.1
done
fi
((sidx++))
done
## switch to first session to begin
dcop $kid konsole activateSession "$sid1" ## switch to 1st session
You can do something similar for any program in any tab. The key to getting
familiar with dcop and finding out what capabilities are available for any
KDE3 app is to just open konsole and type
$ dcop
It will list the applications dcop can communicate with. You can find your
konsole session, (mine is konsole-3380) and then simply type
$ dcop konsole-3380
qt
KBookmarkManager-/home/david/.kde/share/apps/konsole/bookmarks.xml
KBookmarkNotifier
MainApplication-Interface
konsole (default)
konsole-mainwindow#1
ksycoca
session-1
session-10
session-2
session-3
session-4
session-5
session-6
session-7
session-8
session-9
And of course then to see what is available by default:
$ dcop konsole-3380 konsole
QCStringList interfaces()
QCStringList functions()
void feedAllSessions(QString text)
void sendAllSessions(QString text)
int sessionCount()
QString currentSession()
QString newSession()
QString newSession(QString type)
QString sessionId(int position)
void activateSession(QString sessionId)
void nextSession()
void prevSession()
void moveSessionLeft()
void moveSessionRight()
bool fullScreen()
void setFullScreen(bool on)
ASYNC reparseConfiguration()
and you can just work your way down adding the next level of function, etc..
to get exactly what you need, e.g.:
$ dcop konsole-3380 konsole sessionCount
10
Now just weave that into a script for whatever you need to launch (been great
for 5 years plus here, hadn't thought about it since -- until I saw you post)
--
David C. Rankin, J.D.,P.E.