Attaching random commands to a keyboard shortcut

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.

One thought on “Attaching random commands to a keyboard shortcut

  1. yeliaB

    Could this be a case of your muscle memory overcoming your frontal lobes? The reason I ask is that my fl:2 box has no “keyboard_commands”, but it *does* have a “keybinding_commands”…

    Don’t feel bad; it’s basically impossible for me to type the name of the creator of Linux without it coming out as “Linux Torvalds” for the same reason… :-)

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>