JUL
23
2002

Dot Series: Creating Konqueror Service Menus

The ability to select mimetype-specific actions from Konqueror's context menu is an oft-requested feature. The pleasant surprise is that this is already possible. The even more pleasant surprise is that you don't need to be a software developer to do it. This article, the fourth in the dot tutorial series, details step-by-step how to quickly and easily add new actions to Konqueror's context menu.

Comments

The fact that you dressed your two year old son up as a penguin for halloween almost scares me. :)

Great article. I used it to enhance that project I was asking questions about in irc.

--
Evan


By Evan "JabberWok... at Tue, 2002/07/23 - 5:00am

but he's so damn cute as a penguin! i'm hoping that suit will fit him again this year, though i'm doubtful. hrm.. time to start thinking of something equally strange for this October .......

as for the article, i've added two tips to it in response to emails i've received: one for how to make a servicemenu appear for directories (inode/directory as the mimetype) and what to do when you have multiple commands to run (exec a shell! Exec=/bin/sh -c "whatever; whatever && whatever")

these additions should be reflected in the online article shortly...


By Aaron J. Seigo at Tue, 2002/07/23 - 5:00am

It might be worth adding a note about using the UIServer dcop interface to display dialogs too.

Rich.


By Richard Moore at Tue, 2002/07/23 - 5:00am

well, then it starts becoming a tutorial on scripting KDE using dcop rather than a tutorial on making servicemenus. i dipped very briefly into kdcop only to demystify how i got the Exec line in the example.

a general "how to script kde" would make for a great tutorial, though. the topic is large enough to deffinitely warrant its own coverage. i polled people on irc the other evening for tutorial topics that they would like to see, and dcop scripitng was the first one they asked for nearly every time. =)

maybe next month.....


By Aaron J. Seigo at Wed, 2002/07/24 - 5:00am

I guess you mean something like the one Olaf Zanger wrote see http://dot.kde.org/1001577974/ ;-)

Rich.


By Richard Moore at Thu, 2002/07/25 - 5:00am

sort of. but a little less terse, a little more end-user oriented and updated to reflect the newer capabilities of the dcop command line app as well as the newer ones (e.g. dcopfind, dcopref) ... maybe some screenshots of kdcop in action, walking through writing a script step by step ... olaf's paper is great, its just not very accessable to end users and it's a little dated.


By Aaron J. Seigo at Thu, 2002/07/25 - 5:00am

That sounds bloody brilliant. Why don't more people know about this? I tried this and it worked perfectly!

dcop kio_uiserver UIServer messageBox 1 1 "KDE Rules!" "Cool" "yes" "yes!"

I don't know why this one doesn't work:

dcop kio_uiserver UIServer infoMessage 1 "KDE Rules"


By ac at Wed, 2002/07/24 - 5:00am

# dcop kio_uiserver UIServer infoMessage 1 "KDE Rules"
Not enough arguments.

'nough said...


By ineiti at Wed, 2002/07/24 - 5:00am

> dcop kio_uiserver UIServer infoMessage 1 "KDE Rules"

you need a running job to show the message in its progress dialog for this to work AFAIK.


By Aaron J. Seigo at Wed, 2002/07/24 - 5:00am

danke


By tuncer at Tue, 2005/03/29 - 6:00am

My first thought was "Execute with arguments..." but I can't figure out how to handle the dialogs through DCOP. I would love to see a dcop tutorial.


By Chuckie Schumer at Thu, 2002/08/08 - 5:00am

One thing I would like to know is if there is posible to group services created by the user un a submenu. this way you could avoid clutter if you have many services for an espcific mime type


By Mario at Wed, 2002/07/24 - 5:00am

>but he's so damn cute as a penguin! i'm hoping that suit will fit him again this year, though i'm doubtful. hrm.. time to start thinking of something equally strange for this October .......
Will Konqui do? :-) or some BSD demon?


By Alex at Thu, 2002/07/25 - 5:00am

> The fact that you dressed your two year old son up as a penguin for halloween almost scares me. :)

You should've seen me in one, I gotta admit I don't look as cute, but hell, I turn some heads on the streets in it.
Aaron, don't know your wife, but tell her another vegan says hi :)
How do you find the time to do everything you do? KC-KDE, tutorials and huge amounts of super high quality code. Mad props to you for what you do!


By Zack Rusin at Wed, 2002/07/24 - 5:00am

Been wondering about how to do right click actions in KDE, and all along it's been so easy :-)
Will these articles go into the help system? They sure are useful.


By Fredrik C at Wed, 2002/07/24 - 5:00am

This was one of the most interesting bits of information I've read about KDE for a while. I thought I was going to be thinking up stranger and stranger things to do with servicemenus but found myself absorbed by the dcop scripting possibilities instead.

Now I've tried using this dcop thing, it seems to me like it's the KDE killer app. People need to know about this stuff!

Thanks for all the efforts Aaron and the rest of the KDE crowd.

Regards


By Wheely at Wed, 2002/07/24 - 5:00am

Yeah, dcop is amazing. I've been using it in combination with lineak (http://lineak.sourceforge.net/) to enable me to use the "internet keys" on my logitech wireless keyboard. For instance, I can make the "Media" button popup my noatun playlist, and then when I press it again it hides itself! Dcop scripting sets KDE apart, IMHO. Do any other desktops have something like this?


By Matthew Kay at Thu, 2002/07/25 - 5:00am

i remember something vaguely about applescript, which also kicked serious scripting ass. at least at the time; it's been several years since i was in the mac world.


By Aaron J. Seigo at Thu, 2002/07/25 - 5:00am

BTW: is there any central repository where common service-menus are collected?
Would be a great thing for "wow, i always wanted to have this!"-scripts with small efforts but big effects...


By Sebastian Eichner at Wed, 2002/07/24 - 5:00am

not that i know of. you could always start one, though =) ...

if people want to send me the servicemenus they come up with i'll make sure they get up on the web and categorized somewhere.

if we do get a bunch of these together then we'll want a small manager interface for them (turning them on/off, installing new ones, etc) which shouldn't be difficult to do.


By Aaron J. Seigo at Wed, 2002/07/24 - 5:00am

very!! usefull article.
i will try it out @ home today
thanx.
gunnar


By gunnar at Wed, 2002/07/24 - 5:00am

WOW ! Really nice article! I am currently working on a gpg frontend + was able to integrate it to konqueror, adding options to encrypt/decrypt files, but i have one question:

I would like to have my Encrypt file action applied to all file mimetypes.
Is there an easy way to do it ?

Thanks a lot !


By y0k0 at Wed, 2002/07/24 - 5:00am

ServiceTypes=allfiles

it would be nice if one could also do things like image/*


By Aaron J. Seigo at Wed, 2002/07/24 - 5:00am

image/all might work.


By Waldo Bastian at Thu, 2002/07/25 - 5:00am

unfortunately no. i tried that. =(


By Aaron J. Seigo at Thu, 2002/07/25 - 5:00am

ServiceTypes=allfiles

Dawit A.


By Dawit A. at Wed, 2002/07/24 - 5:00am

How would you write an action which brings the image up as an attachment in a kmail composer?


By TCorbin at Thu, 2002/07/25 - 5:00am

/me opens up kdcop and explores for a few seconds

this one looks promising:

dcop kmail KMailIface openComposer to cc bcc subject body hidden messageFile attachURL

i imagine you'd call it something like:

dcop kmail KMailIface openComposer '' '' '' '' '' 0 '' %u

this is completely untested but might get you on your way =)


By Aaron J. Seigo at Thu, 2002/07/25 - 5:00am

THANK YOU!

Not only for this helpful reply, but for all the great work you and
the other kde folks are doing. I absolutely LOVE kde. I think kde
lives up to the promise of the original mac. I haven't been so excited
about computers in a long time.

It's funny, but one of my favorite things about KDE is the file open/save dialog.
Absolutely head and shoulders above anyone else's and it really makes a huge
difference is eas of use.

So anyway - thanks.


By TCorbin at Thu, 2002/07/25 - 5:00am

I tried your example, but it didn't work, so I checked it out with some file in a shell and I got "cannot handle datatype 'KURL'".

How to pass a file using a url of that type?


By ronino at Thu, 2002/07/25 - 5:00am

the current version of dcop apparently doesn't support KURL via the command line. =(

i talked w/waldo about it on IRC today and he's fixed it. now that it is in CVS i suppose we can expect a dcop command line tool that does KURLs in the upcoming beta =)


By Aaron J. Seigo at Thu, 2002/07/25 - 5:00am

Hi,
After seeing this article I started to play around with Konqueror a
small bit and even though my javascript knowledge is next to non-existant
I was able to do a few things ( obviously you need to fill in XXXX and YYYY ):
#change the status bar
dcop konqueror-XXXXX html-widgetYYYY evalJS 'window.status="xxxx"'

#change the background color
dcop konqueror-XXXXX html-widgetYYYY evalJS 'document.bgColor = "blue"

#popping up an alert box
dcop konqueror-XXXXX html-widgetYYYY evalJS "alert(\"my message\")"

#disable javascript for this window
dcop konqueror-XXXXX html-widgetYYYY setJScriptEnabled false

#set the value of the email field in the form when you are
#in the "Post Reply" e.g. http://dot.kde.org/1027447529/addPostingForm
dcop konqueror-XXXXX html-widgetYYYY evalJS "document.forms[0].email.value=\"cph\""
With the above you could easily have a small piece of javascript to set
the username and password on those sites where they do not use cookies
(or where you do not trust them with cookies).

To find out which konqueror html-widgetYYYY you should be using use:
dcop konqueror-XXXXX html-widgetYYYY evalJS "document.title"


By CPH at Thu, 2002/07/25 - 5:00am

Hrmmm... This is all grand. Seriously, this rocks.

But I am wondering if there is something like this for Gnome.
It would be a good thing to make DCOP an independent thing (unless it is already and I am missing out on stuff) and make it work anywhere, KDE, Gnome, or a non-GUI environment.
And it would be a good thing, arguably, to make DCOP interface less binary-dependent, maybe?

KDE ownz!


By MyIS at Thu, 2002/07/25 - 5:00am

> But I am wondering if there is something like this for Gnome.

http://g-scripts.sourceforge.net/


By Anonymous at Thu, 2002/07/25 - 5:00am

he's talking about scripting w/dcop (generic, desktop-wide scripting), not application specific hacks.

looking over that page, however, i see some interesting things about Nautilus that i wasn't aware of, such as:

you need scripts to open files in a given editor? (Konqi just uses mimtypes and offers an Open With-> menu)

showing special file info is done with scripts? (Konqi provide kfilemetainfo, which are actual coded plugins, have their UI integrated w/Konqi and are available to all KDE apps ... hmmmm... perhaps that could be the another article: writing KFMI plugins?)

how do you ensure a script is only available for a given mimetype (e.g. is hidden when it doesn't apply)?

p.s. this isn't meant to bash nautilus at all, these are honest questions i have after reading that page.


By Aaron J. Seigo at Thu, 2002/07/25 - 5:00am

My point is that advanced IPC like DCOP should be separate from a particular desktop suite. Then, competition and natural selection is much more focused - I'd like to be able to pick best parts of all OSS offerings instead of having my choice limited to the two camps.


By MyIS at Fri, 2002/07/26 - 5:00am

the dcop library has bindings to several languages and has very few dependencies itself. AFAIK the only thing it requires is X11 and it's ICE auth mechanism. so pretty much anyone could use it if they were so inclined.


By Aaron J. Seigo at Sat, 2002/07/27 - 5:00am

What you are looking for is Bonobo... it combines the speed of DCOP with the scriptability of KParts.


By ac at Fri, 2002/07/26 - 5:00am

*LOL*


By ac at Fri, 2002/07/26 - 5:00am

Is it possible to change for example the 'copy here/move here/link here' menu that pops up when you drag and drop a file to another directory?

Johan Veenstra


By Johan Veenstra at Fri, 2002/07/26 - 5:00am

No, but that one is in kdebase/libkonq/konq_operations.cc, you can change it there ;)
(what do you want to change about it?)


By David Faure at Fri, 2002/07/26 - 5:00am

> what do you want to change about it?

Disable it because it is bothersome? You almost always want to =move= files. A modifier that allows to copy instead for the very rare cases where you want just that would suffice. As it is now, it looks like newbie stuff that bothers experienced users. And, yes, I know that I can control the behavior by modifiers now.


By Melchior FRANZ at Sat, 2002/07/27 - 5:00am

It would be great to be able to change the "Link Here" behavior to make a hard link rather than a symlink (or maybe add another option)

Assumably to make such a change, I'd have to change the source, and recompile. What kind of undertaking is this? I'll keep looking, but any links to konqueror compilation instructions would be great!

~David.


By David Emerson at Tue, 2004/10/12 - 5:00am

(you're replying to a two-year-old thread, but nevermind :)

http://developer.kde.org/source for how to get the latest sources and compile them.
kdebase/libkonq/konq_operations.cc for where the symlink operation is called. You would have to special case local files and avoid calling KIO::symlink for them, and call link(2) instead. KIO has no support for hardlinks.
Also note that the operation will fail across filesystems...


By David Faure at Tue, 2004/10/12 - 5:00am

Creating service menu entries for file types is very cool...great article. But here's a question for the KDE gurus. How do you create a service menu that pops up when you right click a URL?

Is this even possible?

Thanks

SD


By SD at Sat, 2002/07/27 - 5:00am

Finally I can add menus like "Add to ZIP" or "Add to TGZ"!


By Maciek at Sun, 2002/07/28 - 5:00am

Hello
I found a comment of yours which leads me to beleive that you know how to add functions to the right mouse click in konqueror. PLEASE tell me how. Specifically i want to add the funcions: add to zip, create zip and the same for tgz.
thanks a million for your help.
Ayudame


By ayudame at Sun, 2003/08/31 - 5:00am

I followed the steps. I've got RH7.3 unofficial install of v3.0.2-0unl. It has the ark desktop definition in /usr/share. But the directory didn't even exist in ~/.kde/. Is there some funky permission thing going on?

My file is:

[Desktop Entry]
ServiceTypes=image/png,image/jpeg,image/gif
Actions=setAsWallpaper;setAsTiledpaper

[Desktop Action setAsWallpaper]
Name=Set As Background Image
Icon=background
Exec=dcop kdesktop KBackgroundIface setWallpaper %u 6

[Desktop Action setAsTiledpaper]
Name=Set As Tiled Background Image
Icon=background
Exec=dcop kdesktop KBackgroundIface setWallpaper %u 2

Also, the article said you can edit the file in place and it would automatically update the menu. But, I'm not seeing that happening.

Thanks.


By jp at Mon, 2002/07/29 - 5:00am

is it possible to use this function together with RCS.
For example when i have worked with a file I only hace to
right click on the file and press "New version" or something like that,
write a description of the file and so on.

ci -u %u

would be the command that I want to run I guess but I also want
to add a comment for the change in the file. Is there any solution for
this?

Feel free to mail me a solution

/Andreas


By Andreas Henningsson at Tue, 2002/07/30 - 5:00am