How to add custom keyboard shortcuts in Ubuntu 11.10 Oneiric Ocelot + xdotool

add custom shortcuts ubuntu 
 In Ubuntu 11.10 Oneiric Ocelot it is pretty easy to add a custom shortcut. Just clink the icon on the upper right of the screen, then System Settings > Keyboard > Shortcuts > Custom Shortcuts ( I’m not sure if this names are exact since my Ubuntu is in portuguese, but it should be something like this ). Then you just have to click the “+” to add a new shortcut, name it and write it’s command. After that, apply and then define the keypresses that will call such command. As an example, I defined a shortcut named Banshee which calls the command “banshee” when I press Shift+F4.
Pretty easy, right? However, if you use desktop effects you won’t be able to add a shortcut that runs a script the same way, since metacity is not your window manager. Compiz is.The alternative option would be to fire up gconf-editor and add the command directly under apps >  metacity > keybinding_commands and apps > metacity > global_keybindings. However, it doesnt’t work either. Why? Again, because metacity is not your window manager if you use desktop effects.
So, how to do it? First you have to install the Compiz Config Settings Manager. Launch a terminal ( default keyboard shortcut for launching the terminal is Ctrl+Alt+T ) and run
sudo apt-get install compizconfig-settings-manager
After installing, run
ccsm
Then you just have to click the “Commands” icon in the General section, define the command in the “Commands” tab and the shortcut to launch it in the “Shortcut Keys” tab and that’s it.
As an example, if you wanted to create shortcut keys to control your computer’s volume just like the multimedia keys you could use
xdotool key XF86AudioLowerVolume
to lower the volume and
xdotool key XF86AudioRaiseVolume
to raise your volume. Note that if you don’t have xdotool installed on your computer you need to install it first
sudo apt-get install xdotool
Xdotool is a tool that let’s you simulate keyboard input and mouse activity, move and resize windows, etc. It was developed as a command line X11 automation-tool. For more information check the xdotool project on semicomplete.

Did you find this post helpful? Do you wish to contribute to other projects regarding computer science, electronics, robotics or mechatronics that will be posted in this blog? If you wish to do so, you can donate via paypal using the button below. Thanks! 🙂
 

Donate