Daily Ubuntu / Linux news and application reviews.

ads

I was reading an article on tux-planet.fr about xdotool when I realized I can use this to create a script to focus (activate) the Pidgin conversation window using a shortcut key - something I have been searching for a long time. Being a relatively old ubuntuforums.org member, I also noticed quite a few users were looking for a way of doing this, so I'm guessing this might be interesting for WebUpd8 readers also. Of course, you can use xodotool to focus (or perform many other different actions) any window using the terminal or a script which can be set as a keyboard shortcut, etc.


xdotool is a command line tool for simulating keyboard input and mouse activity, move and resize windows and so on.


To set a keyboard shortcut to focus the Pidgin or Empathy conversion window (of course, it also works for other application with a bit of tweaking), all you have to do is create a script somewhere (like in your home folder), let's call it "winfocus" and paste this inside the newly created file:
#!/bin/bash
WID1=`xdotool search --class "Pidgin" | head -1`;
WID2=`xdotool search --class "Pidgin" | head -2 | tail -1`;
if [[ $WID2 > $WID1 ]]
then xdotool windowactivate $WID2
fi
if [[ $WID2 < $WID1 ]]
then xdotool windowactivate $WID1
fi

You can replace "Pidgin" with "Empathy" if you want.

Update: thanks to jordansissel, here is an even lighter version of the above script:
#!/bin/bash
WID=`xdotool search --class "Pidgin" | head -2 | sort -rn | head -1`;
xdotool windowactivate $WID

Use this instead of the first version. Of course, again: you can replace "Pidgin" with "Empathy" if you want.

Then save the script and make it executable using this command:
chmod +x /path/to/winfocus

Replacing /path/to/ with the exact path to the newly created "winfocus" file.


For the script to work you basically must not have more than 2 Pidgin / Empathy opened windows (the contact list and conversation window) - if you want to use more windows, the script needs to be tweaked. For further help using xdotool, see THIS page.



Of course, make sure you have xdotool for the script to work. In Ubuntu you can install it using the following command:
sudo apt-get install xdotool


Then you can set a keyboard shortcut for running the script.

1. If you use Compiz, go to System > Preferences > CompizConfig Settings Manager, activate the "Commands" plugin then click it and on the first tab called "Commands" enter the exact path to the "winfocus" script and go to the second tab called "Key Bindings" and for the exact same line click on the "disable" button, select "Enable" and then "Grab key combination" to set your shortcut. This is a lot easier than I've explain here but I though I'd cover this also, for those who don't know to set up a keyboard shortcut using CCSM.


2. For Metacity (if you don't use Compiz):

Press Alt + F2 on your keboard and type:
gconf-editor

Then navigate to: apps > metacity > keybinding_commands and choose a "command_x" parameter which is empty. I choose "command_2". Right click it, select "Edit" and enter the exact path to the "winfocus" script.

Now go to apps > metacity > global_keybindings and if you choose "command_2", then right click "run_command_2" and select "Edit", then enter the keys combination you want to use for activating the Pidgin / Empathy conversation window.
«
Next
Newer Post
»
Previous
Older Post