Saturday, May 29, 2010

Add keyboard shortcut on Ubuntu to send user defined signal

Sometimes it is needed to do a task quick and effective on linux, here is when it comes into account keyboard shortcuts.

There is several ways to make this work, but the easiest one I found is just using the default tools provided by Ubuntu.

So, lets say we want to send a user defined signal to a Unix process in our machine to do some specific task asynchronously, that is, when we press the keyboard shortcut. In Windows systems probably we would need to trap events to do something similar.

To do that just go to System - Preferences - keyboard shortcuts and add your command.
In this particular case we want to add:

bash -c -i "kill -USR1 $(pgrep -f your_proccess_name.py)"

Take into account that first we specify the Unix interpreter to be used and then the command.
Kill is sending our user defined signal to our python script, and from that python script we will capture and handle the signal.


1 comment:

Anonymous said...

Thanks.

If you have changed something with gnome-keybinding-properties (for example disabled a keyboard shortcut) but the changes don't work (and F5 or CTRL+R on the desktop don’t solve it) this command can solve the problem:
metacity --replace (you can run it with ALT+F2)

This (re)starts the Metacity window manager.

You can also start Metacity running (but not restart it; only works to start Metacity if another window manager is in use before):
gnome-appearance-properties (also possible from ALT+F2) and setting "Visual Effects" to None

 

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.