[opensuse] Starting apps automatically in console session - SOLVED
Hi all, A while back I asked how to start console apps automatically in a certain konsole session. I just want share the little script I wrote last night: it launches the atop utility in an existing session named "Atop". Might be the general idea behind is useful for somebody out there. That's why I've put a few more comments in it ... Rgds, Stephan. -------------- snip here ----------------------------------------------- #!/bin/sh ### ### Script to start certain apps in konsole sessions automatically. ### ### Requires the "dcop" utility to be installed and the konsoles must ### be started with the "--script" option to enable extended features ### like sendSession. The sessions must exist already. ### ### Here we go ... ### Looking for all konsoles. for i in `dcop konsole\*` ; do ### Checking if the "sendSession" feature available. if [ `dcop $i session-1 functions | grep sendSession | wc -l` -eq 1 ] ; then ### sendSession available, continue. ### Looking for all sessions. for j in `dcop $i | grep session-` ; do ### What's the name ? NAME=`dcop $i $j sessionName` ### If the name matches a predefined session name, launch ### the desired application. if [ "$NAME" = "Atop" ] ; then dcop $i $j sendSession "atop" fi # if [ "$NAME" = ... # add here more names and commands. # fi done else ### sendSession not available. echo "Konsole $i not started with the \"--script\" option". fi done exit 0 -------------- snip here ----------------------------------------------- -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On Sunday 02 December 2007 00:14, Stephan Hegel wrote:
Hi all,
A while back I asked how to start console apps automatically in a certain konsole session.
I just want share the little script I wrote last night: it launches the atop utility in an existing session named "Atop".
That looks handy. I can see using it. You might consider generalizing it a bit. E.g., if a script matching the session name can be found in a particular directory, say $HOME/session-startup/, then that script is launched in the matching session. Then the script need not be modified to accommodate changes in the complement of pre-assigned sessions you want to handle.
Might be the general idea behind is useful for somebody out there. That's why I've put a few more comments in it ...
Assuming an invocation of this script is to be placed in $HOME/.bash_profile, you might want to gracefully handle the case where the shell is running outside of KDE. That includes on virtual consoles, when connecting remotely via ssh and possible when using screen. I don't know if Gnome uses dcop or something else, so it might fail there and under different desktops and window managers as well. In short, be prepared for dcop to fail and do nothing (probably silently) in that case.
Rgds, Stephan.
Randall Schulz -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
Søndag 02 december 2007 16:38 skrev Randall R Schulz:
On Sunday 02 December 2007 00:14, Stephan Hegel wrote:
Hi all,
A while back I asked how to start console apps automatically in a certain konsole session.
I just want share the little script I wrote last night: it launches the atop utility in an existing session named "Atop".
That looks handy. I can see using it.
You might consider generalizing it a bit. E.g., if a script matching the session name can be found in a particular directory, say $HOME/session-startup/, then that script is launched in the matching session. Then the script need not be modified to accommodate changes in the complement of pre-assigned sessions you want to handle.
Might be the general idea behind is useful for somebody out there. That's why I've put a few more comments in it ...
Assuming an invocation of this script is to be placed in $HOME/.bash_profile, you might want to gracefully handle the case where the shell is running outside of KDE. That includes on virtual consoles, when connecting remotely via ssh and possible when using screen. I don't know if Gnome uses dcop or something else, so it might fail there and under different desktops and window managers as well.
In short, be prepared for dcop to fail and do nothing (probably silently) in that case.
Rgds, Stephan.
Randall Schulz
God morning, - how would one be able to detect if the script is being started outside of KDE? Can anyone come up with a short hint ? - thank you! -- ------------------------------------------------------------------------- Med venlig hilsen/Best regards Verner Kjærsgaard Novell Certified Linux Professional 10035701 -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On Monday 03 December 2007 08:34:52 Verner Kjærsgaard wrote:
God morning,
- how would one be able to detect if the script is being started outside of KDE? Can anyone come up with a short hint ? - thank you!
Hi Verner Maybe your script could check with env? Using konsole I get peter@talshiar:~> env | grep KDE KDE_MULTIHEAD=false KDE_NO_IPV6=1 KDE_FULL_SESSION=true KDE_SESSION_UID=1000 peter@talshiar:~> In a text console, nothing shows up. Cheers Pete -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
Mandag 03 december 2007 09:41 skrev Pete Connolly:
On Monday 03 December 2007 08:34:52 Verner Kjærsgaard wrote:
God morning,
- how would one be able to detect if the script is being started outside of KDE? Can anyone come up with a short hint ? - thank you!
Hi Verner
Maybe your script could check with env? Using konsole I get
peter@talshiar:~> env | grep KDE KDE_MULTIHEAD=false KDE_NO_IPV6=1 KDE_FULL_SESSION=true KDE_SESSION_UID=1000 peter@talshiar:~>
In a text console, nothing shows up.
Cheers
Pete
- what can one say? - thank you! -- ------------------------------------------------------------------------- Med venlig hilsen/Best regards Verner Kjærsgaard Novell Certified Linux Professional 10035701 www.os-academy.dk -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
Hi all, Thanks for the feedback, especially Randall's hints for generalization. Also, I've added already a few lines of code to check if dcop is installed and executable. Verner Kjærsgaard wrote:
Søndag 02 december 2007 16:38 skrev Randall R Schulz:
Assuming an invocation of this script is to be placed in $HOME/.bash_profile, you might want to gracefully handle the case where the shell is running outside of KDE. That includes on virtual consoles, when connecting remotely via ssh and possible when using screen. I don't know if Gnome uses dcop or something else, so it might fail there and under different desktops and window managers as well.
In short, be prepared for dcop to fail and do nothing (probably silently) in that case.
Rgds, Stephan. Randall Schulz
God morning,
- how would one be able to detect if the script is being started outside of KDE? Can anyone come up with a short hint ? - thank you! I've made sure that the script is started via the $HOME/.kde/Autostart folder, not in $HOME/.bash_profile or another shell rc file. This makes sure that it is launched only in KDE and that it is launched only once, not with every new shell.
Regards, Stephan. -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 * Stephan Hegel <stephan.hegel@gmx.de> [12-03-07 08:36]: [...]
I've made sure that the script is started via the $HOME/.kde/Autostart folder, not in $HOME/.bash_profile or another shell rc file. This makes sure that it is launched only in KDE and that it is launched only once, not with every new shell.
AND, you *are* going to publish the script ????? tks, - -- Patrick Shanahan Plainfield, Indiana, USA HOG # US1244711 http://wahoo.no-ip.org Photo Album: http://wahoo.no-ip.org/gallery2 Registered Linux User #207535 @ http://counter.li.org -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2 (GNU/Linux) iD8DBQFHVAgnClSjbQz1U5oRApqUAKCjpdYmmc7m89FNp13rzsPmuSrENACeKweG oubFzZ1cav9gV8h92Uy/VqI= =CcZs -----END PGP SIGNATURE----- -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
Stephan Hegel wrote:
Hi all,
Thanks for the feedback, especially Randall's hints for generalization. Also, I've added already a few lines of code to check if dcop is installed and executable.
The best way to learn shell scripting is by looking at other shell scripts which do similar sorts of things. -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
Aaron Kulkis wrote:
Stephan Hegel wrote:
Hi all,
Thanks for the feedback, especially Randall's hints for generalization. Also, I've added already a few lines of code to check if dcop is installed and executable.
The best way to learn shell scripting is by looking at other shell scripts which do similar sorts of things.
Absolutely! I personally have great difficulty without seeing examples. -ED- -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On Monday 03 December 2007 05:29, Stephan Hegel wrote:
Hi all,
Thanks for the feedback, especially Randall's hints for generalization. Also, I've added already a few lines of code to check if dcop is installed and executable.
So now that you've made changes, Patrick's request comes up again (make the script available!). Perhaps you could place the script somewhere accessible to all in its latest form (a server of your own, an entry on the openSUSE Wiki, e.g.). In fact, I think the KDE project itself would allow you to publish it as contributed software. Randall Schulz -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 * Randall R Schulz <rschulz@sonic.net> [12-03-07 20:45]:
So now that you've made changes, Patrick's request comes up again (make the script available!).
Perhaps you could place the script somewhere accessible to all in its latest form (a server of your own, an entry on the openSUSE Wiki, e.g.).
In fact, I think the KDE project itself would allow you to publish it as contributed software.
Or I could make the script available.... - -- Patrick Shanahan Plainfield, Indiana, USA HOG # US1244711 http://wahoo.no-ip.org Photo Album: http://wahoo.no-ip.org/gallery2 Registered Linux User #207535 @ http://counter.li.org -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2 (GNU/Linux) iD8DBQFHVLY+ClSjbQz1U5oRAkl+AJ4i7pYipuE96BR1T62fo31g7wOd0wCfeghh v/2zXW4TzvDGoZZlK8i2A00= =ZcAE -----END PGP SIGNATURE----- -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
* Randall R Schulz <rschulz@sonic.net> [12-03-07 20:45]:
So now that you've made changes, Patrick's request comes up again (make the script available!). Sure, I make it available. Find it below. It's short enough, so I
Hi all, Patrick Shanahan wrote: think I can post it to the mailing list. As mentioned I start it from $HOME/.kde/Autostart to make sure it is started only when KDE is started. It is just a one-liner named "konsoleapps.sh" containing (sleep 5 && $HOME/bin/startkonsoleapps) & .
Or I could make the script available.... Patrick, feel free to do so. And change and adjust it as you like ...
Rgds, Stephan. ---------------------------------------------------------------------------------- #!/bin/sh ### ### startkonsoleapps ### ### Script to start certain apps in KDE konsole sessions. ### ### Requires the "dcop" utility to be installed and the konsoles must ### be started with the "--script option" to enable extended features ### like sendSession. The sessions must already exist. ### ### Executable(s). DCOP=/opt/kde3/bin/dcop ### Location of startup scripts. KONSOLEAPPS=$HOME/.konsoleapps ### Here we go ... ### Checking for system executables. if [ ! -x $DCOP ] ; then echo "$DCOP doesn't exist or isn't executable." exit 1 fi ### Looking for all konsoles. for i in `$DCOP konsole\*` ; do ### Checking if "sendSession" feature available. if [ `$DCOP $i session-1 functions | grep sendSession | wc -l` -eq 1 ] ; then ### Function sendSession available, continue. ### Looking for all sessions. for j in `$DCOP $i | grep session-` ; do ### What's the name ? NAME=`$DCOP $i $j sessionName` ### If the name matches a predefined session name, launch ### the desired application. if [ -x $KONSOLEAPPS/$NAME ] ; then $DCOP $i $j sendSession "$KONSOLEAPPS/$NAME" fi done else ### Function sendSession not available. echo "Konsole $i not started with the \"--script\" option". fi done exit 0 ----------------------------------------------------------------------------------- -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
participants (7)
-
Aaron Kulkis
-
Ed McCanless
-
Patrick Shanahan
-
Pete Connolly
-
Randall R Schulz
-
Stephan Hegel
-
Verner Kjærsgaard