4

I am using the LXDE desktop environment, which is based on Openbox. I know how to change the key-bindings by editing my ~/.config/openbox/lxde-rc.xml, e.g.:

<keybind key="A-F11">
  <action name="ToggleFullscreen"/>
</keybind>

However, I need to make a non-persistent change, which will only be effective for the current session. And I need to make this change from the command line, without editing the XML file.

Is that possible?

  • Is it always the same key combination + action or might there be some variation in the action or key combination? – Raphael Ahrens Mar 30 '16 at 8:50
  • @Raphael Ahrens - basically I just need to change one key-binding (always the same). Lets take the ToggleFullscreen example shown in my original post. I need to assign Escape key instead of A-F11. – Martin Vegter Mar 30 '16 at 12:35
  • It sound like you want to enter into fullscreen with A-F11 and exit it with Escape. There are "Chrooting key chains" which would work for this example but your question sounds more general. – Raphael Ahrens Mar 30 '16 at 12:50
  • @Raphael Ahrens - This is just an example for illustration. In this example, I want to change the keybinding to toggle full-screen with Escape, instead of A-F11 – Martin Vegter Mar 30 '16 at 13:37
0

When I used openbox a few years ago I found OBHotkey helpful. There's a command line interface and a tray icon as well.

I can't remember if I had to pair this with xdotool to get what I wanted out of it, but you should be able to make it work pretty easily.

0

here's a solution with bash, a fiddly language to write !

 #!/usr/bin/bash

 RCXML='rc.xml'

 find=$(cat $RCXML | grep -i -B 1 $1 | head -2)

 editkeys=$(cat $RCXML | grep -i -B 1 $1 | head -1)

 echo ''
 echo '  FOUND THE FOLLOWING SHORTCUT:'
 echo " ${find}"
 echo ''
 echo '  EDITING ABOVE KEYBIND TO:'
 echo "     <keybind key=\"$2\">"
 echo ''
 echo '  HIT ENTER TO CONFIRM.'
 read y

 if [ -z $y ]; then
     sed -i "s/$editkeys/\ \ \ \ <keybind key=\"$2\">/g" $RCXML
 fi

example of use:

 bash rcedit.sh ToggleShowD C-S-u

note: if you have the same keybinding for two different things, it uses the last one in the file. and this script edits the first one it finds by action name e.g. toggledesktop. but obviously you could edit it to find by keybinding, though keybindings are obviously less likely to be unique

the script needs to be in the same folder as the rc.xml unless you specify the full path in the RCXML variable, and note that globbing/tilda doesn't work in a variable

also, if you want to edit custom made shortcuts, which include the extra line:

 <action name="Execute">

you will have to adjust the bash script to include that extra line:

 find=$(cat $RCXML | grep -i -B 2 $1 | head -3)
 editkeys=$(cat $RCXML | grep -i -B 2 $1 | head -1)

if you want to edit mousekey shortcuts you'll have to do alot more editing

i tried for a little while to create something that appreciates the XML format more, with ruby, though the fact that the action name entry is nested inside the keybind key, is kind of the wrong way round to code an easy solution. also, the rc.xml file is packed with comment lines, which confused the two ruby XML modules i tried. but if you strip those out, you might be able to make something in ruby.

you could also append the following lines to .bashrc

 alias backuprcxml="~/.config/openbox/lxde-rc.xml > ~/.config/openbox/lxde-rc.xml.backup"
 alias restorercxml="~/.config/openbox/lxde-rc.xml.backup > ~/.config/openbox/lxde-rc.xml"

so then run this once to create a backup:

 backuprcxml

then add the following line to: ~/.config/openbox/autostart

 ~/.config/openbox/lxde-rc.xml.backup > ~/.config/openbox/lxde-rc.xml
  • @nfinite-etcetera - I appreciate the effort you put into answering my question. But I find the offered solution too "ugly". I was hoping for some "clean" way to do it. – Martin Vegter Mar 23 '16 at 17:11
  • meeeeep. but maybe i will use it – infinite-etcetera Mar 25 '16 at 13:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.