@ Dotan: As requested (back in March, sorry): Hotkey launcher scripts

Duncan 1i5t5.duncan at cox.net
Sat Oct 27 12:50:27 BST 2012

Duncan posted on Tue, 13 Mar 2012 16:12:03 +0000 as excerpted:

>>> [1] When kde4 broke multi-key hotkeys that worked just fine in kde3, I
>>> rolled my own solution.  I'm not a C/C++ or even python/perl coder,
>>> only a bash scriptor, so I coded the script in bash and run it in a
>>> special konsole window with its own kwin window rules.  It's not
>>> fancy,
>>> but it does a rather impressive job, considering it's all bash and
>>> kwin rules, picking up where all kde4 left me was broken pieces of a
>>> solution that USED to work!  A kde single-key hotkey still launches my
>>> script tho there's independent hotkey solutions out there too, if kde
>>> decides to break that as well.  My script in turn takes a category and
>>> then an action selection key, to launch anything I use often enough to
>>> have programmed a sequence for in a total of three individual key
>>> presses.
>>> For example, to open my browser of choice to bank's secure login site
>>> is launcher, n, b.  Launcher is an "extra" key available on my
>>> inet/media keyboard, n=net (category), b=bank (individual task in the
>>> selected category).
>> I would love to see your scripted hotkeys bash file. I use Krunner very
>> heavily, and your solution might be even more efficient.
> FWIW, it's actually a collection of several files, an initial trigger
> script, the main menu script, a keymap file that maps ctrl-key hotkeys
> (normal printing characters and shifted chars are native, ctrl-key
> combos need the mapping file and some like ctrl-J, newline, don't work
> anyway, it's just those three variants, normal, shifted and controlled),
> and of course the menu files.  The menu files are user owned/configured,
> the others are placed under the /usr/local/ location as system files.
> There's actually a bit of kde config that goes along with it too.  I
> mentioned the kwin window rules and the single khotkeys based trigger
> key above.  The last bit of the puzzle is that I run a separate konsole
> profile for the menu, tho I believe it's optional.  (I tried it along
> the way, and had it setup when I got the thing working, so left it
> setup, but I don't think it's actually necessary.)
> I'll probably post the collection, along with appropriate instructions,
> later.  I'm too tired to compose the instructions properly, ATM.

OK, this is *MUCH* later, but I still had this marked unread in ordered 
to deal with later, and I'm finally getting the appropriately rounded 
tuit. =:^)

There are two executable scripts and one kmap file, placed in a "system" 
location, and as many user menu files as desired.  One menu file is 
invoked first, but invocation is nestable, so it's possible for the first 
one to invoke the scripts again, thus invoking an additional layer of 

Here, I have two menu layers, a primary that selects the category (net, 
config, games, etc), and a second, category menu, that launches the 
desired action.  It's thus three keys to launch anything I have 
configured an action for, the kde-launcher key (to launch the scripts 
with the primary menu), the category selector key (select the category 
and launch that menu), and the action selector key (launch the app/action 
configured for that key).  (Originally, I had a single layer menu, much 
larger, thus requiring only two keys.  But that got unwieldy, so I added 
a layer of indirection and a key to the sequence, breaking it into pieces 
arrange by category.)

I'll post the files separately as replies.  This is the instructions for 
setting them up and using them.

First, create a separate konsole profile called "hkm" (without the 
quotes, hkm being short for hotkey menu).  This allows you to setup 
different behavior for it than for your normal konsole.  Here, my hkm 
konsole profile has a MUCH smaller scrollback menu of only a hundred 
lines, for instance, and I have the scrollbar set hidden, while it's 
shown on my normal konsole profile.  If you like you can also set a 
distinctive font and background.

(You could skip the separate konsole profile or name it something else, 
but if you do, you have to change the launcher script accordingly, since 
it invokes the menu script with the "--profile hkm" option.)

Second, create a new window rule for the menu.  If you don't already have 
a window rule for your normal konsole windows, you'll probably want to 
create one for them as well, setting anything you want to behave 
differently than the konsole menu windows.

(The following description is for kde 4.9, other versions might be 
slightly different.  I'm describing the English terms, I'm not sure how 
much of this might be localized.  Window rules are found in kde settings, 
workspace appearance and behavior, window behavior, window rules.)

On the window matching tab, set window class to "exact match" "konsole 
konsole", and check "match whole window class".  Set window role to 
"substring match", "mainwindow#".  Set window types to "normal window".  
Set window title to "substring match" "Hotkey Menu".  The window title 
bit is extremely important, since otherwise this rule will likely match 
ALL konsole windows.  I actually had quite some trouble getting the rule 
to apply ONLY to my menu windows, not all konsole windows, as I wanted 
different window behavior.  So if you change or localize this, as with 
the konsole profile bit above, be SURE to change the launcher script 
accordingly, or you won't get a match!

On the size and position tab, this is what I found works best for me: 
Size checked, apply initially, 740,610.  (Change the size as needed for 
best menu display.  If you change your fonts, this will need to change as 
well.  Again, this is different behavior than my normal konsole windows, 
which have their own window rules.  Since konsole will try to use the 
same size as the last time and I wanted a different size for my menu 
konsoles, I had to set it specifically.  Maximized horizontally and 
maximized vertically, checked, apply initially, no.  (The rule for my 
normal konsole windows maximizes vertically.  Different behavior here, so 
I have to set the rule.)  Initial placement, checked, force, centered.  
(You can experiment here, but I found my default "smart" window placement 
policy did NOT work well for the menu, mostly because whatever it 
launched then ended up in the wrong spot.  Under mouse might be another 
good choice.)  Minimum size, checked, force, 640,480.  (Again, this 
differs from the setting I use for my normal konsole windows.)

On the appearance and fixes tab, focus stealing prevention, checked, 
force, none.  You'll be invoking with a hotkey and you always want it to 
appear and activate, so no focus stealing prevention.  (Without this, the 
menu would sometimes appear unfocused, under whatever I was working on.  

That's the window-rules setup for the menu.  OK and apply.

Third, still in kde settings, setup the key you want to invoke the menu.  
Common appearance and behavior, shortcuts and gestures, custom shortcuts.

If you haven't setup any of your own shortcuts here before, I suggest you 
create a new group.  That's found under the edit button.  Choose a name 
for your customized settings.  Here, I used my initials (JED).

Select that group and edit, new, global shortcut, command/url.  Set the 
title.  Here, I called it Hotkey-menu.  

On the trigger tab, choose a launcher key.  Here, on my main system I 
have a fancy internet/media keyboard with a whole bunch of "extra" keys, 
so I use one of them, HomePage.  On my netbook, I decided to use winkey-
space (winkey aka superkey aka hyperkey, depending on who you ask or 
where you read about it) as the menu launcher.

On the action tab, set the command to "hkl" (hotkey launcher).  That's 
the name of the launcher script.  Of course you can rename it as 
desired.  The command here just has to match the name of the launcher 

Hit apply, and you should be done setting up kde for use with the menu.  
Now you just need the files.  =:^)

The first script, hkl (hotkey launcher), is real short, just the shebang 
and a single command (split here into two lines), so I'll include it 
here.  Modify the shebang and command as desired, but be sure to take 
note above if you change the --title or --profile options, and of course 
if you change the name of the second script from hkm, change the -e 
invocation of it here, as well.

-------------- begin hkl -----------------

exec konsole --nofork --title "Hotkey Menu" --profile hkm \
 --hide-tabbar --hide-menubar -e hkm "$@"

-------------- end hkl --------------------

Save that file somewhere in your path, and set it executable.  I put it 
in the system's local bin dir, /usr/local/bin/, here.

The second script file, hkm (hotkey menu) is the hairy guts of the 
thing.  I place it in /usr/local/bin/ as well, of course set executable.  
This script is well commented.

There's a number of default settings near the top of the script, which 
you can change as desired.  These include the location of the menu files 
(in the hotkey.lst subdir under $XDG_CONFIG_HOME if it's set, with 
~/.config/ the default for XDG_CONFIG_HOME if it's not set), and the 
location of the keymap file (normally /usr/local/etc/hotkeylookup.lst, 
see below).

There's three additional settings with a global value set here, that can 
be overridden in the individual menu files if desired.  These include a 
30-second query-timeout after which the default key is invoked, a post-
launch timeout of 3 seconds, useful to see any errors spit out if 
something doesn't launch, but you may wish to shorten this, and a global 
default-key, normally escape (to cancel the menu), invoked if no key is 
hit by the query-timeout.  (See the in-script comments for per-menu-file 
override instructions.)

There's also a keymap file, hotkeylookup.lst, used to translate control-
modified keys, thus giving you three hotkeys to choose from for most 
letters, unmodified, shifted, and controlled.  If you're happy with only 
unmodified and shifted (no controlled), you can do without the keymap 
file.  I place this file in /usr/local/etc/ here, but that's one of the 
script settings I mentioned above as changeable.  This file has control 
characters in it, so I'll have to attach it encoded.  I'll use UUE, which 
most clients should have no problem with.

(It's worth noting that the other xorg key modifiers, alt and winkey, get 
"lost" in the interface between xorg, konsole, and the shell.  So using a 
bash script, the only thing I know well enough to hack this up in, 
unmodified, shifted, and controlled, are the only reliable options.  Even 
then, a few of them are "reserved".  ^C ^J and ^M are SIGINT, linefeed 
and carriagereturn respectively, and cannot be used as hotkeys.)

I'll also post a couple example menu files.

So four posts should follow, one each for the hkm menu script, the 
hotkeylookup.lst keymap file, and two example user menu scripts.

Duncan - List replies preferred.   No HTML msgs.
"Every nonfree program has a lord, a master --
and if you use the program, he is your master."  Richard Stallman

This message is from the kde mailing list.
Account management:  https://mail.kde.org/mailman/listinfo/kde.
Archives: http://lists.kde.org/.
More info: http://www.kde.org/faq.html.

More information about the kde mailing list