Opening files from Gnome Commander in foreground

Gnome Commander is my preferred file commander on linux, it’s simple and it works. However, I usually map F3 to my preferred editor (gedit) rather than use the internal viewer and when you do that, gedit is not brought into the foreground if it is already open. Which is totally lame. Luckily there’s an easy way to fix it. Create a script named e.g. gedit-foreground.sh with the following content:


#!/bin/sh
gedit $1
wmctrl -a gedit

Obviously you can modify this to open any app if you prefer. Save this in your home directory somewhere and then make it executable using:

chmod a+x gedit-foreground.sh

Then install wmctrl using:

sudo apt-get install wmctrl

Now in Gnome Commander go to Settings->Options->Programs and set the viewer to:

/path/to/your/scripts/gedit-foreground.sh %s

Now when you press F3 or whatever your key for ‘open in external viewer’ is, your editor will be launched and be brought to the foreground instantly!