Tricky KDE icon

The place to post if you need help or advice

Moderators: ChrisThornett, LXF moderators

Tricky KDE icon

Postby Lancer » Sun May 01, 2005 6:20 pm

I'm wanting to make a launcher / icon for KDE which will help me in teaching Linux to school children. Basically, wherever the icon is placed, when clicked on in Konqueror, it should launch a terminal saying the directory it is in. Opening the icon with a text editor gives the following...

Code: Select all
[Desktop Entry]
Comment=
Comment[en_GB]=
Encoding=UTF-8
Exec=echo; echo " You clicked me in directory..."; echo -n " "; pwd; echo;
GenericName=
GenericName[en_GB]=
Icon=emacs
MimeType=
Name=Where_am_I
Name[en_GB]=Where_am_I
Path=
StartupNotify=true
Terminal=true
TerminalOptions=--noframe --noscrollbar --notabbar --notoolbar --nomenubar --noresize --vt_sz 35x5 -T "You clicked me!" --noclose
Type=Application
Version=1.0
X-DCOP-ServiceType=none
X-KDE-SubstituteUID=false
X-KDE-Username=


The problem is, when clicked the icon always gives the users $HOME directory. Any idea on how to make it display the directory it resides in?

P.S. I'm using KDE launcher (as above) because for the other exercises I'm putting together (and the age of some of the students) it's important to have kid-friendly icons on the clickable scripts.
Lancer
LXF regular
 
Posts: 232
Joined: Thu Apr 07, 2005 11:59 am

RE: Tricky KDE icon

Postby Guest » Wed May 04, 2005 12:49 pm

Try creating a shell script, and providing a link to it.
Guest
 

RE: Tricky KDE icon

Postby Lancer » Fri May 06, 2005 10:53 am

Nope. That method does not work for I suspect the same reason.
Lancer
LXF regular
 
Posts: 232
Joined: Thu Apr 07, 2005 11:59 am

RE: Tricky KDE icon

Postby nelz » Fri May 06, 2005 11:39 am

That reason being that you are always in the home directory when you run the script. What you need is the scripts directory, something like this

Code: Select all
#!/bin/sh
echo "The current directory is $(dirname $0)"
"Insanity: doing the same thing over and over again and expecting different results." (Albert Einstein)
User avatar
nelz
Site admin
 
Posts: 8469
Joined: Mon Apr 04, 2005 11:52 am
Location: Warrington, UK

RE: Tricky KDE icon

Postby Lancer » Sat May 07, 2005 1:12 am

Nearly there I think

Linking to the script has the problem of echo "The current directory is $(dirname $0)" returning the directory of the original script... not the desktop shortcut / KDE icon location I want. What this means is that students cannot move the KDE icon around into different directories, click it and have it report "I am now in <whereever they moved the icon>".

I tried embedding the $(dirname $0) function into the KDE destop icon itself like so...
Exec=echo " You clicked me in directory..."; echo " $(dirname $0)";
...but that only returns "."

I guess another way would be to actually move a shell script around which itself opens a terminal like so...

Code: Select all
#!/bin/bash
xterm -geometry 50x3 -bg black -fg green +sb -T "You clicked me" -hold -e echo "I am in directory $(dirname $0)"


...this works :mrgreen: but has the following disadvantage: There seems to be no way of changing the icon to a custom one without affecting all other occurances of *.sh type files. For classroom exercises I want to have a range of icons which do different things (open xterm with different messages), and each should look different. This is why I had been trying to do use a KDE desktop icon for the job. Is there a work around?
Lancer
LXF regular
 
Posts: 232
Joined: Thu Apr 07, 2005 11:59 am

RE: Tricky KDE icon

Postby Lancer » Sat May 07, 2005 1:32 am

Kool! Under Gnome, I can right click the icon to properties and then just choose custom icon for that one application :) Now if only I could do the same in KDE...
Lancer
LXF regular
 
Posts: 232
Joined: Thu Apr 07, 2005 11:59 am

Re: RE: Tricky KDE icon

Postby fdgdfgdf » Sun May 15, 2005 2:43 pm

fdgdfgdf
 

RE: Re: RE: Tricky KDE icon

Postby skecs » Mon May 16, 2005 7:36 am

Lancer - you can in KDE.

Simply right-click on the desktop, choose "Create New => File =>Link to application" and browse to your shell script or whatever.

Complete the name, comments, description, etc. Select OK and your desktop link appears.

Right click (or do this before selecting OK) and on the General tab you'll see the curent icon or shortcut, simply click on this and you will have a number of standard icons available or browse and choose your own. This only affects the current link.
Regards from
Downunder!
.... _
... (0)>
... / /\
.. / / .)
.. V_/_
Linux Powered!
User avatar
skecs
 
Posts: 76
Joined: Fri Apr 22, 2005 9:22 am
Location: Bathurst, NSW Australia

RE: Re: RE: Tricky KDE icon

Postby Lancer » Mon May 16, 2005 9:49 am

Ah.... but you miss the whole point. If I do it that way, the address in the shell script does not return the address location of the shortcut icon, but only that of where the original shell script is located. I want to make an icon which can be dragged from dir to dir and when clicked on launches an alert or shell reading "I am in xxx directory".
Lancer
LXF regular
 
Posts: 232
Joined: Thu Apr 07, 2005 11:59 am

RE: Re: RE: Tricky KDE icon

Postby jjmac » Mon May 16, 2005 11:58 am

Would using a perl script help. Or trying to do a 'cd' first, before the other cmds are executed ?


jm

Code: Select all

 -:-  If the system is the answer, then the question
                   must have been really stupid                -:-
http://counter.li.org
#313537

The FVWM wm -=- www.fvwm.org -=-

Somebody stole my air guitar, It happened just the other day,
But it's ok, 'cause i've got a spare ...
jjmac
LXF regular
 
Posts: 1996
Joined: Fri Apr 08, 2005 1:32 am
Location: Sydney, Australia

RE: Re: RE: Tricky KDE icon

Postby Guest » Mon May 16, 2005 6:20 pm

Perl is not something I'm proficient in. If you can get any script to work, please show me.

If you could 'cd' to a location, then surely you would be able to echo/printf that location as well.

The trick here is in transfering the location of the icon itself into the script. I can get it to work in Gnome by setting an individual icon to the shell script which launches the an xterm (the script was the last one I showed). However, this will not work under KDE, as there appears to be no sensible way of assigning a custom icon to an individual script. Once you make a shortcut/link to a script, no one seems to know of a useable variable which would give the location of the original shortcut/link icon.
Guest
 

RE: Re: RE: Tricky KDE icon

Postby Lancer » Mon May 16, 2005 6:28 pm

Last post was me. :roll:
(Sets mode to 'notify')
Lancer
LXF regular
 
Posts: 232
Joined: Thu Apr 07, 2005 11:59 am

RE: Re: RE: Tricky KDE icon

Postby nelz » Mon May 16, 2005 10:31 pm

I don't see how the language used would make any difference.
"Insanity: doing the same thing over and over again and expecting different results." (Albert Einstein)
User avatar
nelz
Site admin
 
Posts: 8469
Joined: Mon Apr 04, 2005 11:52 am
Location: Warrington, UK

RE: Re: RE: Tricky KDE icon

Postby jjmac » Tue May 17, 2005 1:25 am

>>
The trick here is in transfering the location of the icon itself into the script. I can get it to work in Gnome by setting an individual icon to the shell script which launches the an xterm (the script was the last one I showed). However, this will not work under KDE, as there appears to be no sensible way of assigning a custom icon to an individual script
>>

Yes, i can see what you mean... Perl being what it is, i just though it may well have some magic along those lines hidden away somewhere.

Tricky. But then,... is it really a good idea to have icons following you around your fs to easily. What if your in a sensitive area, then so will it, opening up potential problems. Especially if for some bug, it decided to stay there..

Maybe a seperate menu branch in the filemanager might be more practical

Maybe ... if you could get the filemanager to write to a file in your $HOME directory, reflecting directory changes. Then ... if the icon can source that file first, then do a cd based on the path string found there ... By sourcing, i mean, using the "Exec=' config option in the above file example.

... but as you say, show an example, hmmm. Some ideas at least :)


Appended:

After a few tests ...

I could get it to invoke an rxvt window, but if i tryed to get it to do more, such as with the '-e' switch, or using '&&', even trying to pipe 'ls' to 'rxvt' (grin), all that happened was that the shell would flash open .. then close.


I think it boils down to the icon belonging to the original session shell that the wm itself is bound to. Rather than being a child of that.

If it could be made to have it's own shell when it is created ... then there might be a chance to move it about ?!

I think thats basically what was hapening with your gnome test.

jm

Code: Select all
  -:-  If the system is the answer, then the question
                     must have been really stupid              -:-
jjmac
LXF regular
 
Posts: 1996
Joined: Fri Apr 08, 2005 1:32 am
Location: Sydney, Australia

RE: Re: RE: Tricky KDE icon

Postby jjmac » Wed May 18, 2005 9:35 am

Just to clarify what i mean above.

>>
I guess another way would be to actually move a shell script around which itself opens a terminal like so...


Code:
#!/bin/bash
xterm -geometry 50x3 -bg black -fg green +sb -T "You clicked me" -hold -e echo "I am in directory $(dirname $0)"
[/code]

...this works but has the following disadvantage:
>>

It will still gives you the directory of the script.

A long way round solution ...

Grep through the file managers source and look for the function that retrives the current directory, as reflected in the file managers window.

What ever variable is used there ... use it to write that path to a file in your own HOME directory. Overwriting it each time.
Then, have the script retrieve the saved string contained in it.

Recompile the manager with an altered name, so as the extra burden of continuously writing to the file wont hold you down for ordinary usage.

I know ... greping through source can be a pain, but ... is there really another way to overcome the problem of the icon and the script being in a different working directories as to the file managers navigation.

I must be missing your point somewhere though, as part of your original comment ...

>>
Basically, wherever the icon is placed, when clicked on in Konqueror, it should launch a terminal saying the directory it is in
>>

i find a bit confusing ...

How can you get a desktop icon to follow a filemanager/browsers tree navigation. ???

How do you get the root window in a file manager. Can kde really do that (grin) wow ...

sorry if i've been wasting your time there :), it just seemed alike a really interesting delima, from my interpretation ... which may well be missing your point. As i get the felling that your suggesting that the icon should change directories as you do. Doesn't solve the script being where ever it is ... but i cant see how the icon could travel about. Unless its the directory icon ... hmmm, i guess that must be what you mean there.

jm

Code: Select all

 -|-  If the system is the answer, then the question
                  must have been really stupid                -|-
jjmac
LXF regular
 
Posts: 1996
Joined: Fri Apr 08, 2005 1:32 am
Location: Sydney, Australia

Next

Return to Help!

Who is online

Users browsing this forum: Google [Bot] and 0 guests