Tuesday, May 31, 2011

krunner doing just one thing

So here's a feature of KRunner than probably very few of you know about: KRunner can be made to query a single specific plugin for one search. You can even quite easily create shortcuts, both launchers and global keyboard shortcuts, to trigger this behavior. This feature was added some time ago by Jacopo, but it's rather well hidden unless you know it is there or stumble over it accidentally.

If you've played with KRunner, you probably have found the configuration where you can turn plugins on or off by pressing the left-most button with the icon of a wrench/spanner tool on it. This is something different, however.

Here is KRunner searching only for Applications on my machine:



Here it is looking only at command line operations:



You can do that with any of the following plugins (by plugin ID) in 4.7: recentdocuments, org.kde.windowedwidgets, locations, kabccontacts, bookmarks, org.kde.activities, solid, webshortcuts, shell, services, PowerDevil, wikipedia, nepomuksearch, desktopsessions, windows. This is accomplished by having a Runner plugin which either can match whole search terms or which registers a default syntax using AbstractRunner::setDefaultSyntax(const RunnerSyntax &). As long as the Runner plugin matches one of those criteria, then this line in the .desktop file for the plugin makes the magic happen: X-Plasma-AdvertiseSingleRunnerQueryMode=true. Unfortunately, in previous releases only a handful of plugins were marked this way. I've fixed this for 4.7.0 however. :)

To trigger the "single plugin" behaviour, you can create a launcher on a panel or desktop that calls to KRunner via D-Bus like this: "qdbus org.kde.krunner /App displaySingleRunner nepomuksearch". To get a list of possible values for that last entry, try this from a konsole: "qdbus org.kde.krunner /App singleModeAdvertisedRunnerIds".

The other way, and perhaps even more convenient, is to open the global keyboard shortcuts panel (type "global key" in KRunner :) and go to the Run Command Interface selection in the drop down box at the top of the window:



Then you can assign a keyboard shortcut to your favorite plugin. This means that you can, for instance, turn Nepomuk searches off in the main KRunner config and only when you want to search the files on your disk press the key combo for that runner. The rest of the time, the Nepomuk (or whatever other plugin you turn off in the KRunner config) won't be queried for normal searches done via Alt+F2 or "Run Command" from a launcher.

Pretty sweet, huh? :)

4 comments:

Luís said...

Sweet! Now I know what to do with all that extra buttons my laptop came with ;) Just an idea, though. Would it make sense for krunner to assume a different visual aspect according to the particular runner being used? For example: be wider and show context on nepomuk results; or be vertically elongated and show more actions and bigger icons when using the akonadi contacts runner. I don't know if this is feasible or even desirable but seems to fit the single runner use-case. Cheers and keep up with the good work.

Thijs said...

Hypercool! That looks like a very efficient activity switcher in the very near future . However, the fact that 'very few' probably knew, and indeed that I didnt know about it despite my regular visits to (global) keyboard shortcuts & krunner usage, suggests that something should be done about the discoverability.
Same held for for instance the advanced math functions of the krunner-calculator.

Wouldn't it be sensible to be able to set these shortcuts in the settings of the particular runner?

Alessandro Nakamuta said...
This comment has been removed by the author.
Alessandro Nakamuta said...

It's really usefull. A sugestion is implement keywords, like google-chrome and firefox on their search engines. E.g. tiping "ap chrome", query chrome only in applications. Google chrome behaviour is interesting, because when we tip the keyword, the word is replaced with a box informing what the search engine is using. So, typing "ap(space)", the search can be replaced with the application only query, and pressing backspace, the search can be replaced again with the query all again (with only word ap in it).