I thought I should share this simple way to run a command with a key combination.
Metacity will let you configure keyboard shortcuts for generating events it knows about (sound events, window events etc). For that, all you have to do is go to System->Preference->Keyboard Shortcuts.
But what if you wanted to run an arbitrary command? In my case, if I suspend my laptop while the display is set to use the external monitor, and I resume trying to use the laptop’s LCD screen, I would have to somehow invoke xrandr to get the display back. Sounds like a keyboard shortcut would solve the problem, since I could type it blindly, without anything on the display.
This is the solution I found:
- Run gconf-editor
- Go to apps->metacity->keyboard_commands
- edit one of the command_N keys to add the command you want to be run (in my case xrandr)
- go to global_keybindings, edit the run_command_N key and add the keyboard shortcut, like <Ctrl><Alt><Shift>R
No need to restart anything.