Modify Openbox key-bindings from commandline

command linekeyboard shortcutslxdeopenbox

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?

Best Answer

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
Related Question