syntax highlight

Saturday 31 January 2009

Changing default shortcuts in gnome

Another of those thing I usually forget: changing default shortcut actions in gnome. In this case, I'm using MOC as my music player (see apt-get install new computer II and while it's great it won't integrate nicely with gnome. Fortunately (as most GNU/Linux applications do) it can be commanded via CLI so it isn't hard to change this.

Now, gnome keyboard shortcuts already have defined actions, so how can we change them to invoke  a custom command? Easy enough:
  1. Open gconf-editor
  2. Go to apps > metacity > keybinding_commands
  3. Set a command from the list. In my case I'm going to set command_1 to "mocp -S", command_2 to "mocp -f" and command_3 to "mocp -r"
  4. Go to apps > metacity > global_keybinding
  5. Set the corresponding run_command_* to the keyboard shortcut. For me that's 0xA2 for run_command_1, 0xE9 for run_command_2 and 0xEA for run_command_3; beware it changes between keyboards.
Troubleshooting tips:
  • If you use gconf-editor for a key binding don't use it again System > Preferences > Key bindings
  • For hex value keybindings (like the ones I used on the example) use uppercase
  • If it's not working and you can't figure out why try with an already working command and a simple keybinding (e.g. gnome-screenshot and ctrl-p) then change each one in turn, see where it breaks. Divide and conquer!!