Running a script in kde?

There must be a simple answer…

I want to write a bash script which could be run from a terminal or within KDE - how can I find out within the script where it’s running?

Basically I want to switch between a simple echo statement on the terminal or kdialog if I’m in KDE

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

You could always try the kdialog command and perhaps check the
errorlevel if it fails.

textToBePrinted=‘put your text for the message here’;
kdialog -msgbox “$textToBePrinted” 2>/dev/null
if $? != 0 ]; then echo ‘$textToBePrinted’; fi

Good luck.

In theory that checks to see if kdialog fails and, if it does, prints
text to the screen.

fudokai wrote:
| There must be a simple answer…
|
| I want to write a bash script which could be run from a terminal or
| within KDE - how can I find out within the script where it’s running?
|
| Basically I want to switch between a simple echo statement on the
| terminal or kdialog if I’m in KDE
|
|
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFIb3Xx3s42bA80+9kRApqOAJ9ZcsiAxuZqrrz4zNoKnnHh6fxs/gCdGJAr
E2/jYCjD0JCA9TxbeN+bjLM=
=IrB2
-----END PGP SIGNATURE-----

ab@novell.com wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> You could always try the kdialog command and perhaps check the
> errorlevel if it fails.
>
> textToBePrinted=‘put your text for the message here’;
> kdialog -msgbox “$textToBePrinted” 2>/dev/null
> if $? != 0 ]; then echo ‘$textToBePrinted’; fi
>
> Good luck.
>
>
>
>
>
> In theory that checks to see if kdialog fails and, if it does, prints
> text to the screen.
>
> fudokai wrote:
> | There must be a simple answer…
> |
> | I want to write a bash script which could be run from a terminal or
> | within KDE - how can I find out within the script where it’s running?
> |
> | Basically I want to switch between a simple echo statement on the
> | terminal or kdialog if I’m in KDE
> |
> |
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.2 (GNU/Linux)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
>
> iD8DBQFIb3Xx3s42bA80+9kRApqOAJ9ZcsiAxuZqrrz4zNoKnnHh6fxs/gCdGJAr
> E2/jYCjD0JCA9TxbeN+bjLM=
> =IrB2
> -----END PGP SIGNATURE-----

That works but it’s a bit messy - I was hoping I could set a variable at the
start of the script and then test for that wherever I need it.

Alan


email =~ s/nospam/fudokai/

It works but it’s a bit messy - I’d rather set a variable at the start of the script and test for it whenever I need to.

Alan

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

That’s fine. Do the test and instead of having the ‘echo’ command for
the command line set a variable instead to be used from then on.

textToBePrinted=‘put your text for the message here’;
kdialog -msgbox “$textToBePrinted” 2>/dev/null
if $? != 0 ]; then export NOGUI=1; fi

#From then on:

if $NOGUI ]; then
echo "$textToBePrinted
else
kdialog -msgbox “$textToBePrinted” 2>/dev/null
fi

Still not perfect. You may be able to semi-reliably test the existing
environment for variables like XAUTHORITY. There are probably better
ways as well.

Good luck.

ajp wrote:
| ab@novell.com wrote:
|
| You could always try the kdialog command and perhaps check the
| errorlevel if it fails.
|
| textToBePrinted=‘put your text for the message here’;
| kdialog -msgbox “$textToBePrinted” 2>/dev/null
| if $? != 0 ]; then echo ‘$textToBePrinted’; fi
|
| Good luck.
|
|
|
|
|
| In theory that checks to see if kdialog fails and, if it does, prints
| text to the screen.
|
| fudokai wrote:
| | There must be a simple answer…
| |
| | I want to write a bash script which could be run from a terminal or
| | within KDE - how can I find out within the script where it’s running?
| |
| | Basically I want to switch between a simple echo statement on the
| | terminal or kdialog if I’m in KDE
| |
| |

| That works but it’s a bit messy - I was hoping I could set a variable
at the
| start of the script and then test for that wherever I need it.

| Alan

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFIcMA/3s42bA80+9kRAvQYAJ9tmuzlfK6wPeBXAxzjKGlHZ1zTkACghKBz
w2bvLYLFMTFmdMDb0/Q6j/w=
=6ji4
-----END PGP SIGNATURE-----

Ok - using
-n $KDE_SESSION_UID ]] && kdialog …
-n $KDE_SESSION_UID ]] || echo …
seems to work :slight_smile: